The math routines allow you to perform common mathematical calculations. All math routines work with floating-point values and therefore require floating-point support (see “Floating-Point Support”).
The math library provides two versions of some routines. The first version of the routine supports double arguments and return values. The second version supports an 80-bit data type, allowing the routine to take long double arguments and return a long double value. The second version usually has the same name with the suffix l. For instance, the acos routine supports double arguments and return values, while _acosl supports long double arguments and return values.
Routines which support long double values are not available when you compile with the /FPa (alternate math) compiler option. The same is true of the _clear87, _control87, and _status87 routines.
Most math declarations are in the include file MATH.H. However, the _clear87, _control87, _fpreset, and _status87 routines are defined in FLOAT.H; the abs and labs functions are defined in MATH.H and STDLIB.H; and the div and ldiv routines are declared in STDLIB.H.
Routine | Use |
acos, _acosl | Calculate the arccosine |
asin, _asinl | Calculate the arcsine |
atan, _atanl | Calculate the arctangent |
atan2, _atan2l | Calculate the arctangent |
Bessel | Calculates Bessel functions |
_cabs, _cabsl | Find the absolute value of a complex number |
ceil, _ceill | Find the integer ceiling |
_clear87 | Gets and clears the floating-point status word |
_control87 | Gets the old floating-point control word and sets a new control-word value |
cos, _cosl | Calculate the cosine |
cosh, _coshl | Calculate the hyperbolic cosine |
_dieeetomsbin | Converts IEEE double-precision number to Microsoft (MS) binary format |
div | Divides one integer by another, returning the quotient and remainder |
_dmsbintoieee | Converts Microsoft binary double-precision number to IEEE format |
exp, _expl | Calculate the exponential function |
fabs, _fabsl | Find the absolute value |
_fieeetomsbin | Converts IEEE single-precision number to Microsoft binary format |
floor, _floorl | Find the largest integer less than or equal to the argument |
fmod, _fmodl | Find the floating-point remainder |
_fmsbintoieee | Converts Microsoft binary single-precision number to IEEE format |
_fpreset | Reinitializes the floating-point-math package |
frexp, _frexpl | Calculate an exponential value |
_hypot, _hypotl | Calculate the hypotenuse of a right triangle |
ldexp, _ldexpl | Calculate the product of the argument and 2exp |
ldiv | Divides one long integer by another, returning the quotient and remainder |
log, _logl | Calculate the natural logarithm |
log10, _log10l | Calculate the base-10 logarithm |
_lrotl, _lrotr | Shift an unsigned long int item left (_lrotl) or right (_lrotr) |
_matherr, _matherrl | Handle math errors |
__max, __min | Return the larger or smaller of two values |
modf, _modfl | Split the argument into integer and fractional parts |
pow, _powl | Calculate a value raised to a power |
rand | Gets a pseudorandom number |
_rotl, _rotr | Shift an unsigned int item left (_rotl) or right (_rotr) |
sin, _sinl | Calculate the sine |
sinh, _sinhl | Calculate the hyperbolic sine |
sqrt, _sqrtl | Find the square root |
srand | Initializes a pseudorandom series |
_status87 | Gets the floating-point status word |
tan, _tanl | Calculate the tangent |
tanh, _tanhl | Calculate the hyperbolic tangent |
The Bessel routine does not correspond to a single function, but to 12 functions named _j0, _j1, _jn, _y0, _y1, _yn, _j0l, _j1l, _jnl, _y0l, _y1l, and _ynl.
The _matherr and _matherrl routines are invoked by the math functions when errors occur. The _matherr routine handles functions that return a double value, and _matherrl handles routines that return a long double.
These routines are defined in the library, but you can redefine them for different error handling. The user-defined function, if given, must follow the rules given in the reference description of _matherr and _matherrl.
You are not required to supply a definition for the _matherr routines. If no definition is present, the default error returns for each routine are used. The reference description of each routine describes that routine's error returns.