Math Functions
- Most complex math functions are part of a library.
- #include <cmath>
- Most come in several "flavors"
- absolute value
- int abs(int)
- Takes an int as a parameter
- Returns an integer result
- long abs(long)
- Same, but with a long.
- float fabs(float)
- This one actually is multiple functions, it returns the floating point type it takes
- long double fabs(long double)
- Power functions
- float pow(float, float)
- pow(2,10) computes 210
- For the entire float family
- float sqrt(float)
- For the entire float family.
- Trig functions
- sin, cos, tan
- acos, atan, atan2, ...
- All are float, double, long double
- Work in radians, not degrees
- This is just a taste, most functions are available.
- Math Constants
- There are a number of predefined math constants as well.
- look at (with your editor) /usr/include/math.h
- M_PI and various values
- M_E and associated log values
- M_SQRT2, the square root of 2.
- Look at /usr/include/limits.h
- This gives you size limits for most numeric types.