Standard C Libraries - Math Functions. More...
Go to the source code of this file.
Functions | |
double | acos (double x) |
float | acosf (float x) |
double | asin (double x) |
float | asinf (float x) |
double | atan (double x) |
float | atanf (float x) |
double | atan2 (double y, double x) |
float | atan2f (float y, float x) |
double | ceil (double x) |
float | ceilf (float x) |
double | cos (double x) |
float | cosf (float x) |
double | cosh (double x) |
float | coshf (float x) |
double | exp (double x) |
float | expf (float x) |
double | fabs (double x) |
float | fabsf (float x) |
double | floor (double x) |
float | floorf (float x) |
double | fmod (double x, double y) |
float | fmodf (float x, float y) |
double | frexp (double x, int *exp) |
float | frexpf (float x, int *exp) |
double | ldexp (double x, int ex) |
float | ldexpf (float x, int ex) |
double | log (double x) |
double | log10 (double x) |
float | log10f (float x) |
float | logf (float x) |
double | modf (double x, double *pint) |
float | modff (float x, float *pint) |
double | pow (double x, double y) |
float | powf (float x, float y) |
double | sin (double x) |
float | sinf (float x) |
double | sinh (double x) |
float | sinhf (float x) |
double | sqrt (double x) |
float | sqrtf (float x) |
double | tan (double x) |
float | tanf (float x) |
double | tanh (double x) |
float | tanhf (float x) |
Standard C Libraries - Math Functions.
The header file, math.h, consists of a macro and various functions that calculate common mathematical operations. Error conditions may be handled with a domain error or range error (see errno.h). A domain error occurs when the input argument is outside the domain over which the function is defined. The error is reported by storing the value of EDOM in errno and returning a particular value defined for each function. A range error occurs when the result is too large or too small to be represented in the target precision. The error is reported by storing the value of ERANGE in errno and returning HUGE_VAL if the result overflowed (return value was too large) or a zero if the result underflowed (return value is too small). Responses to special values, such as NaNs, zeros and infinities, may vary depending upon the function. Each function description includes a definition of the function’s response to such values.
The documentation in this header file has been copied from the documentation provided with the Microchip MPLAB XC16 compiler. The original license agreement included with the XC16 compiler applies!
double acos | ( | double | x) |
Description: Calculates the trigonometric arc cosine function of a double precision floating-point value.
Include: <math.h>
x | value between -1 and 1 for which to return the arc cosine |
Remarks:
A domain error occurs if x is less than -1 or greater than 1.
Example:
Output:
Error: domain error
The arccosine of -2.000000 is nan
The arccosine of 0.100000 is 1.470629
float acosf | ( | float | x) |
Description: Calculates the trigonometric arc cosine function of a single precision floating-point value.
Include: <math.h>
x | value between -1 and 1 |
Remarks:
A domain error occurs if x is less than -1 or greater than 1.
Example:
Output:
Error: domain error
The arccosine of 2.000000 is nan
The arccosine of 0.000000 is 1.570796
double asin | ( | double | x) |
Description: Calculates the trigonometric arc sine function of a double precision floating-point value.
Include: <math.h>
x | value between -1 and 1 for which to return the arc sine |
Remarks:
A domain error occurs if x is less than -1 or greater than 1.
Example:
Output:
Error: domain error
The arcsine of 2.000000 is nan
The arcsine of 0.000000 is 0.000000
float asinf | ( | float | x) |
Description: Calculates the trigonometric arc sine function of a single precision floating-point value.
Include: <math.h>
x | value between -1 and 1 |
Remarks:
A domain error occurs if x is less than -1 or greater than 1.
Example:
Output:
Error: domain error
The arcsine of 2.000000 is nan
The arcsine of 0.000000 is 0.000000
double atan | ( | double | x) |
Description: Calculates the trigonometric arc tangent function of a double precision floating-point value.
Include: <math.h>
x | value for which to return the arc tangent |
Remarks:
No domain or range error will occur.
Example:
Output:
The arctangent of 2.000000 is 1.107149
The arctangent of -1.000000 is -0.785398
double atan2 | ( | double | y, |
double | x | ||
) |
Description: Calculates the trigonometric arc tangent function of y/x.
Include: <math.h>
y | value for which to return the arc tangent |
x | value for which to return the arc tangent |
Remarks:
A domain error occurs if both x and y are zero or both x and y are +/- infinity.
Example:
Output:
The arctangent of 2.000000/0.000000 is 1.570796
The arctangent of 0.000000/-1.000000 is 3.141593
Error: domain error
The arctangent of 0.000000/0.000000 is nan
float atan2f | ( | float | y, |
float | x | ||
) |
Description: Calculates the trigonometric arc tangent function of y/x.
Include: <math.h>
y | value for which to return the arc tangent |
x | value for which to return the arc tangent |
Remarks:
A domain error occurs if both x and y are zero or both x and y are +/- infinity.
Example:
Output:
The arctangent of 2.000000/0.000000 is 1.570796
The arctangent of 0.000000/-1.000000 is 3.141593
Error: domain error
The arctangent of 0.000000/0.000000 is nan
float atanf | ( | float | x) |
Description: Calculates the trigonometric arc tangent function of a single precision floating-point value.
Include: <math.h>
x | value for which to return the arc tangent |
Remarks:
No domain or range error will occur.
Example:
Output:
The arctangent of 2.000000 is 1.107149
The arctangent of -1.000000 is -0.785398
double ceil | ( | double | x) |
Description: Calculates the ceiling of a value.
Include: <math.h>
x | a floating-point value for which to return the ceiling |
Remarks:
No domain or range error will occur. See floor.
Example:
Output:
The ceiling for 2.000000 is 2.000000
The ceiling for 1.750000 is 2.000000
The ceiling for 1.500000 is 2.000000
The ceiling for 1.250000 is 2.000000
The ceiling for -2.000000 is -2.000000
The ceiling for -1.750000 is -1.000000
The ceiling for -1.500000 is -1.000000
The ceiling for -1.250000 is -1.000000
float ceilf | ( | float | x) |
Description: Calculates the ceiling of a value.
Include: <math.h>
x | floating-point value |
Remarks:
No domain or range error will occur. See floorf.
Example:
Output:
The ceiling for 2.000000 is 2.000000
The ceiling for 1.750000 is 2.000000
The ceiling for 1.500000 is 2.000000
The ceiling for 1.250000 is 2.000000
The ceiling for -2.000000 is -2.000000
The ceiling for -1.750000 is -1.000000
The ceiling for -1.500000 is -1.000000
The ceiling for -1.250000 is -1.000000
double cos | ( | double | x) |
Description: Calculates the trigonometric cosine function of a double precision floating-point value.
Include: <math.h>
x | value for which to return the cosine |
Remarks:
A domain error will occur if x is a NaN or infinity.
Example:
Output:
The cosine of -1.000000 is 0.540302
The cosine of 0.000000 is 1.000000
float cosf | ( | float | x) |
Description: Calculates the trigonometric cosine function of a single precision floating-point value.
Include: <math.h>
x | value for which to return the cosine |
Remarks:
A domain error will occur if x is a NaN or infinity.
Example:
Output:
The cosine of -1.000000 is 0.540302
The cosine of 0.000000 is 1.000000
double cosh | ( | double | x) |
Description: Calculates the hyperbolic cosine function of a double precision floating-point value.
Include: <math.h>
x | value for which to return the hyperbolic cosine |
Remarks:
A range error will occur if the magnitude of x is too large.
Example:
Output:
The hyperbolic cosine of -1.500000 is 2.352410
The hyperbolic cosine of 0.000000 is 1.000000
Error: range error
The hyperbolic cosine of 720.000000 is inf
float coshf | ( | float | x) |
Description: Calculates the hyperbolic cosine function of a single precision floating-point value.
Include: <math.h>
x | value for which to return the hyperbolic cosine |
Remarks:
A range error will occur if the magnitude of x is too large.
Example:
Output:
The hyperbolic cosine of -1.000000 is 1.543081
The hyperbolic cosine of 0.000000 is 1.000000
Error: range error
The hyperbolic cosine of 720.000000 is inf
double exp | ( | double | x) |
Description: Calculates the exponential function of x (e raised to the power x where x is a double precision floating-point value).
Include: <math.h>
x | value for which to return the exponential |
Remarks:
A range error occurs if the magnitude of x is too large.
Example:
Output:
The exponential of 1.000000 is 2.718282
Error: range error
The exponential of 1000.000000 is inf
Error: range error
The exponential of -1000.000000 is 0.000000
float expf | ( | float | x) |
Description: Calculates the exponential function of x (e raised to the power x where x is a single precision floating-point value).
Include: <math.h>
x | floating-point value for which to return the exponential |
Remarks:
A range error occurs if the magnitude of x is too large.
Example:
Output:
The exponential of 1.000000 is 2.718282
Error: range error
The exponential of 1000.000000 is inf
Error: range error
The exponential of -1000.000000 is 0.000000
double fabs | ( | double | x) |
Description: Calculates the absolute value of a double precision floating-point value.
Include: <math.h>
x | floating-point value for which to return the absolute value |
Remarks:
No domain or range error will occur.
Example:
Output:
The absolute value of 1.750000 is 1.750000
The absolute value of -1.500000 is 1.500000
float fabsf | ( | float | x) |
Description: Calculates the absolute value of a single precision floating-point value.
Include: <math.h>
x | floating-point value for which to return the absolute value |
Remarks:
No domain or range error will occur.
Example:
Output:
The absolute value of 1.750000 is 1.750000
The absolute value of -1.500000 is 1.500000
double floor | ( | double | x) |
Description: Calculates the floor of a double precision floating-point value.
Include: <math.h>
x | floating-point value for which to return the floor |
Remarks:
No domain or range error will occur. See ceil.
Example:
Output:
The floor for 2.000000 is 2.000000
The floor for 1.750000 is 1.000000
The floor for 1.500000 is 1.000000
The floor for 1.250000 is 1.000000
The floor for -2.000000 is -2.000000
The floor for -1.750000 is -2.000000
The floor for -1.500000 is -2.000000
The floor for -1.250000 is -2.000000
float floorf | ( | float | x) |
Description: Calculates the floor of a single precision floating-point value.
Include: <math.h>
x | floating-point value |
Remarks:
No domain or range error will occur. See ceilf. Standard C Libraries - Math Functions ? 2010 Microchip Technology Inc. DS51456G-page 167
Example:
Output:
The floor for 2.000000 is 2.000000
The floor for 1.750000 is 1.000000
The floor for 1.500000 is 1.000000
The floor for 1.250000 is 1.000000
The floor for -2.000000 is -2.000000
The floor for -1.750000 is -2.000000
The floor for -1.500000 is -2.000000
The floor for -1.250000 is -2.000000
double fmod | ( | double | x, |
double | y | ||
) |
Description: Calculates the remainder of x/y as a double precision value.
Include: <math.h>
x | a double precision floating-point value |
y | a double precision floating-point value |
Remarks:
If y = 0, a domain error occurs. If y is non-zero, the result will have the same sign as x and the magnitude of the result will be less than the magnitude of y.
Example:
Output:
For fmod(7.000000, 3.000000) the remainder is 1.000000
For fmod(7.000000, 7.000000) the remainder is 0.000000
For fmod(-5.000000, 3.000000) the remainder is -2.000000
For fmod(5.000000, -3.000000) the remainder is 2.000000
For fmod(-5.000000, -5.000000) the remainder is -0.000000
Error: domain error
For fmod(7.000000, 0.000000) the remainder is nan
float fmodf | ( | float | x, |
float | y | ||
) |
Description: Calculates the remainder of x/y as a single precision value.
Include: <math.h>
x | a single precision floating-point value |
y | a single precision floating-point value |
Remarks:
If y = 0, a domain error occurs. If y is non-zero, the result will have the same sign as x and the magnitude of the result will be less than the magnitude of y.
Example:
Output:
For fmodf (7.000000, 3.000000) the remainder is 1.000000
For fmodf (-5.000000, 3.000000) the remainder is -2.000000
For fmodf (5.000000, -3.000000) the remainder is 2.000000
For fmodf (5.000000, -5.000000) the remainder is 0.000000
Error: domain error
For fmodf (7.000000, 0.000000) the remainder is nan
For fmodf (7.000000, 7.000000) the remainder is 0.000000
double frexp | ( | double | x, |
int * | exp | ||
) |
Description: Gets the fraction and the exponent of a double precision floating-point number.
Include: <math.h>
x | floating-point value for which to return the fraction and exponent |
exp | pointer to a stored integer exponent |
Remarks:
The absolute value of the fraction is in the range of 1/2 (inclusive) to 1 (exclusive). No domain or range error will occur.
Example:
Output:
For frexp of 50.000000
the fraction is 0.781250
and the exponent is 6
For frexp of -2.500000
the fraction is -0.625000
and the exponent is 2
For frexp of 0.000000
the fraction is 0.000000
and the exponent is 0
float frexpf | ( | float | x, |
int * | exp | ||
) |
Description: Gets the fraction and the exponent of a single precision floating-point number.
Include: <math.h>
x | floating-point value for which to return the fraction and exponent |
exp | pointer to a stored integer exponent |
Remarks:
The absolute value of the fraction is in the range of 1/2 (inclusive) to 1 (exclusive). No domain or range error will occur.
Example:
Output:
For frexpf of 0.150000
the fraction is 0.600000
and the exponent is -2
For frexpf of -2.500000
the fraction is -0.625000
and the exponent is 2
For frexpf of 0.000000
the fraction is 0.000000
and the exponent is 0
double ldexp | ( | double | x, |
int | ex | ||
) |
Description: Calculates the result of a double precision floating-point number multiplied by an exponent of 2.
Include: <math.h>
x | floating-point value |
ex | integer exponent |
Remarks:
A range error will occur on overflow or underflow.
Example:
Output:
For a number = -0.625000 and an exponent = 2
ldexp(-0.625000, 2) = -2.500000
For a number = 2.500000 and an exponent = 3
ldexp(2.500000, 3) = 20.000000
Error: range error
For a number = 15.000000 and an exponent = 10000
ldexp(15.000000, 10000) = inf
float ldexpf | ( | float | x, |
int | ex | ||
) |
Description: Calculates the result of a single precision floating-point number multiplied by an exponent of 2.
Include: <math.h>
x | floating-point value |
ex | integer exponent |
Remarks:
A range error will occur on overflow or underflow.
Example:
Output:
For a number = -0.625000 and an exponent = 2
ldexpf(-0.625000, 2) = -2.500000
For a number = 2.500000 and an exponent = 3
ldexpf(2.500000, 3) = 20.000000
Error: range error
For a number = 15.000000 and an exponent = 10000
ldexpf(15.000000, 10000) = inf
double log | ( | double | x) |
Description: Calculates the natural logarithm of a double precision floating-point value.
Include: <math.h>
x | any positive value for which to return the log |
Remarks:
A domain error occurs if x ? 0.
Example:
Output:
The natural logarithm of 2.000000 is 0.693147
The natural logarithm of 0.000000 is -inf
Error: domain error
The natural logarithm of -2.000000 is nan
double log10 | ( | double | x) |
Description: Calculates the base-10 logarithm of a double precision floating-point value.
Include: <math.h>
x | any double precision floating-point positive number |
Remarks:
A domain error occurs if x ? 0.
Example:
Output:
The base-10 logarithm of 2.000000 is 0.301030
The base-10 logarithm of 0.000000 is -inf
Error: domain error
The base-10 logarithm of -2.000000 is nan
float log10f | ( | float | x) |
Description: Calculates the base-10 logarithm of a single precision floating-point value.
Include: <math.h>
x | any single precision floating-point positive number |
Remarks:
A domain error occurs if x ? 0.
Example:
Output:
The base-10 logarithm of 2.000000 is 0.301030
Error: domain error
The base-10 logarithm of 0.000000 is -inf
Error: domain error
The base-10 logarithm of -2.000000 is nan
float logf | ( | float | x) |
Description: Calculates the natural logarithm of a single precision floating-point value.
Include: <math.h>
x | any positive value for which to return the log |
Remarks:
A domain error occurs if x ? 0.
Example:
Output:
The natural logarithm of 2.000000 is 0.693147
The natural logarithm of 0.000000 is -inf
Error: domain error
The natural logarithm of -2.000000 is nan
double modf | ( | double | x, |
double * | pint | ||
) |
Description: Splits a double precision floating-point value into fractional and integer parts.
Include: <math.h>
x | double precision floating-point value |
pint | pointer to a stored the integer part |
Remarks:
The absolute value of the fractional part is in the range of 0 (inclusive) to 1 (exclusive). No domain or range error will occur.
Example:
Output:
For 0.707000 the fraction is 0.707000
and the integer is 0
For -15.212100 the fraction is -0.212100
and the integer is -15
float modff | ( | float | x, |
float * | pint | ||
) |
Description: Splits a single precision floating-point value into fractional and integer parts.
Include: <math.h>
x | single precision floating-point value |
pint | pointer to stored integer part |
Remarks:
The absolute value of the fractional part is in the range of 0 (inclusive) to 1 (exclusive). No domain or range error will occur.
Example:
Output:
For 0.707000 the fraction is 0.707000
and the integer is 0
For -15.212100 the fraction is -0.212100
and the integer is -15
double pow | ( | double | x, |
double | y | ||
) |
Description: Calculates x raised to the power y.
Include: <math.h>
x | the base |
y | the exponent |
Remarks:
If y is 0, pow returns 1. If x is 0.0 and y is less than 0, pow returns inf and a domain error occurs. If the result overflows or underflows, a range error occurs.
Example:
Output:
-2.000000 raised to 3.000000 is -8.000000
3.000000 raised to -0.500000 is 0.577350
4.000000 raised to 0.000000 is 1.000000
Error: domain error
0.000000 raised to -3.000000 is inf
float powf | ( | float | x, |
float | y | ||
) |
Description: Calculates x raised to the power y.
Include: <math.h>
x | base |
y | exponent |
Remarks:
If y is 0, powf returns 1. If x is 0.0 and y is less than 0, powf returns inf and a domain error occurs. If the result overflows or underflows, a range error occurs.
Example:
Output:
-2.000000 raised to 3.000000 is -8.000000
3.000000 raised to -0.500000 is 0.577350
Error: domain error
0.000000 raised to -3.000000 is inf
double sin | ( | double | x) |
Description: Calculates the trigonometric sine function of a double precision floating-point value.
Include: <math.h>
x | value for which to return the sine |
Remarks:
A domain error will occur if t x is a NaN or infinity.
Example:
Output:
The sine of -1.000000 is -0.841471
The sine of 0.000000 is 0.000000
float sinf | ( | float | x) |
Description: Calculates the trigonometric sine function of a single precision floating-point value.
Include: <math.h>
x | value for which to return the sine |
Remarks:
A domain error will occur if x is a NaN or infinity.
Example:
Output:
The sine of -1.000000 is -0.841471
The sine of 0.000000 is 0.000000
double sinh | ( | double | x) |
Description: Calculates the hyperbolic sine function of a double precision floating-point value.
Include: <math.h>
x | value for which to return the hyperbolic sine |
Remarks:
A range error will occur if the magnitude of x is too large.
Example:
Output:
The hyperbolic sine of -1.500000 is -2.129279
The hyperbolic sine of 0.000000 is 0.000000
Error: range error
The hyperbolic sine of 720.000000 is inf
float sinhf | ( | float | x) |
Description: Calculates the hyperbolic sine function of a single precision floating-point value.
Include: <math.h>
x | value for which to return the hyperbolic sine |
Remarks:
A range error will occur if the magnitude of x is too large.
Example:
Output:
The hyperbolic sine of -1.000000 is -1.175201
The hyperbolic sine of 0.000000 is 0.000000
double sqrt | ( | double | x) |
Description: Calculates the square root of a double precision floating-point value.
Include: <math.h>
x | a non-negative floating-point value |
Remarks:
If x is negative, a domain error occurs.
Example:
Output:
The square root of 0.000000 is 0.000000
The square root of 9.500000 is 3.082207
Error: domain error
The square root of -25.000000 is nan
float sqrtf | ( | float | x) |
Description: Calculates the square root of a single precision floating-point value.
Include: <math.h>
x | non-negative floating-point value |
Remarks:
If x is negative, a domain error occurs.
Example:
Output:
The square root of 0.0F is 0.000000
The square root of 9.5F is 3.082207
Error: domain error
The square root of -25F is nan
double tan | ( | double | x) |
Description: Calculates the trigonometric tangent function of a double precision floating-point value.
Include: <math.h>
x | value for which to return the tangent |
Remarks:
A domain error will occur if x is a NaN or infinity.
Example:
Output:
The tangent of -1.000000 is -1.557408
The tangent of 0.000000 is 0.000000
float tanf | ( | float | x) |
Description: Calculates the trigonometric tangent function of a single precision floating-point value.
Include: <math.h>
x | value for which to return the tangent |
Remarks:
A domain error will occur if x is a NaN or infinity.
Example:
Output:
The tangent of -1.000000 is -1.557408
The tangent of 0.000000 is 0.000000
double tanh | ( | double | x) |
Description: Calculates the hyperbolic tangent function of a double precision floating-point value.
Include: <math.h>
x | value for which to return the hyperbolic tangent |
Remarks:
No domain or range error will occur.
Example:
Output:
The hyperbolic tangent of -1.000000 is -0.761594
The hyperbolic tangent of 2.000000 is 0.964028
float tanhf | ( | float | x) |
Description: Calculates the hyperbolic tangent function of a single precision floating-point value.
Include: <math.h>
x | value for which to return the hyperbolic tangent |
Remarks:
No domain or range error will occur.
Example:
Output:
The hyperbolic tangent of -1.000000 is -0.761594
The hyperbolic tangent of 0.000000 is 0.000000