fpclassify | classify floating point type |
isfinite | test for finite |
isinf | test for infinity |
isnan | test for NaN |
isnormal | test for normal |
signbit | test sign bit of floating point value |
acos | arc cosine |
asin | arc sine |
atan | arc tangent |
atan2 | arc tangent in 4 quadrants |
ceil | round upwards |
cos | cosine |
cosh | hyperbolic cosine |
cbrt | cube root |
exp | ex |
exp2 | 2x |
expm1 | ex - 1 |
fabs | absolute value |
floor | round downwards |
fmod | remainder after division |
frexp | extract exponent and mantissa |
hypot | hypotenuse |
ilogb | logarithm base 2 |
ldexp | n*2exp |
log | natural logarithm |
log2 | base-2 logarithm |
logb | logarithm base 2 |
log10 | logarithm base 10 |
log1p | natural logarithm of (1 + x) |
matherr, _matherrl | handle errors generated by math functions |
modf | separate value into integral and fractional parts |
nextafter | next representable value |
poly | compute polynomial |
pow | xy |
sin | sine |
sinh | hyperbolic sine |
sqrt | square root |
tan | tangent |
tanh | hyperbolic tangent |
_cabs | absolute value of complex number |
#include <math.h> int fpclassify(x);
Value | Meaning |
---|---|
FP_NANS | Signalling NaN |
FP_NANQ | Quiet NaN |
FP_NAN | Quiet NaN (same as FP_NANQ) |
FP_INFINITE | Infinity |
FP_NORMAL | A number not covered by other classifications |
FP_SUBNORMAL | Subnormal or denormal |
FP_ZERO | Zero |
FP_EMPTY | No value |
FP_UNSUPPORTED | Unsupported bit pattern |
Return Value
Returns a constant that reflects the class of the floating-point expression x.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
#include <math.h> int isfinite(x); int isinf(x); int isnan(x); int isnormal(x);
Function | Test |
---|---|
isfinite | is normal, subnormal or zero |
isinf | is infinity |
isnan | is a NaN |
isnormal | is not zero, infinity, subnormal, or NaN |
#include <math.h> int signbit(x);
Return Value
Non-zero if the sign bit is 1; zero if the sign bit is 0.
Compatibility
C99 7.12.3.6
Return Value
The arc cosine of x.
x | return value | invalid? |
---|---|---|
>1.0 | NAN | yes |
<-1.0 | NAN | yes |
NAN | NAN | yes |
See Also
asin, atan, atan2, cos, cosh, hypot, sin, sinh, tan, tanh
Example
/* Example of acos */ #include <math.h> #include <stdio.h> #include <stdlib.h> void main() { double d; double result; printf("Enter a double:"); scanf("%lg", &d); result = acos(d); printf("\nacos(%lg) = %lg\n", d, result); }Output
Enter a double:. 45
acos(0.45) = 1.10403
Prototype
double asin(double x);
float asinf(float x);
long double asinl(long double x);
Return Value
The arcsine of x. Each function returns a value ranging from -π/2 to π/2. For asinl, if the x argument is outside the range of -1 to 1, the function returns NAN (not a number) and errno is set to EDOM, for domain error.
Special Results
value of x return value invalid? ±0.0 ±0.0 no >1.0 NAN yes <-1.0 NAN yesCompatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
acos
atan
atan2
cos
cosh
hypot
sin
sinh
tan
tanh Functions
Example
/* Example of asin */ #include <math.h> #include <stdio.h> #include <stdlib.h> void main() { double d; printf("Enter a double : "); scanf("%lg", &d); printf("\nasin(%g) = %g\n", d, asin(d)); }Output
Enter a double :. 45
asin(0.45) = 0.466765
Prototype
double atan(double x);
float atanf(float x);
long double atanl(long double x);
Return Value
The arc tangent of x. This is a value in the range of -π/2 to π/2.
Special Results
value of x return value invalid? ±0.0 ±0.0 no ±INFINITY NAN yesCompatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
acos
asin
atan2
cos
cosh
hypot
sin
sinh
tan
Example
/* Example of atan */ #include <math.h> #include <stdio.h> #include <stdlib.h> void main() { double d; printf("Enter a double : "); scanf("%lg", &d); printf("\natan(%g) = %g\n", d, atan(d)); }Output
Enter a double :. 45
atan(0.45) = 0.422854
Prototype
double atan2(double y, double x);
float atan2f(float y, float x);
long double atan2l(long double y, long double x);
Return Value
The arc tangent of y/x. This is a value in the range -π to π. If one argument is a NaN, than NaN is returned; if both arguments are NaNs, either one may be returned.
If both arguments are 0, these functions set errno to EDOM, print a _DOMAIN error message to stderr, and return 0.
Special Results
value of y value of x return value ±0.0 > 0.0 ±0.0 ±0.0 ±0.0 ±0.0 ±0.0 < 0.0 ±π ±0.0 -0.0 ±π > 0.0 ±0.0 π/2 < 0.0 ±0.0 π/2 > 0.0 INFINITY ±0.0 ±INFINITY anything ±π/2 > 0.0 -INFINITY ±π ±INFINITY INFINITY ±π/4 ±INFINITY -INFINITY ±3π/4Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
acos
asin
atan
atan2
cos
cosh
hypot
sin
sinh
tan
tanh
Example
/* Example of atan2 */ #include <math.h> #include <stdio.h> #include <stdlib.h> void main() { double d1, d2; printf("Enter two doubles : "); scanf("%lg %lg", &d1, &d2); printf("\natan2(%g, %g) = %g\n", d1, d2, atan2(d1,d2)); }Output
Enter two doubles :. 3 .4
atan2(0.3, 0.4) = 0.643501
x | return value | invalid? |
---|---|---|
±0.0 | ±0.0 | no |
NAN | NAN | yes |
±INFINITY | ±INFINITY | no |
Prototype
double ceil(double x);
float ceilf(float x);
long double ceill(long double x);
Return Value
x rounded up to the next integer.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
floor
nearbyint
rint
rndtol
rndtonl
round
trunc
Example
/* Example for ceil */ #include <math.h> #include <stdio.h> #include <stdlib.h> void main() { double d; printf("Enter a double: "); scanf("%lg",& d); printf("\nCeil (%lg) = %lg\n", d, ceil(d)); }Output
Enter a double: 3.34
Ceil (3.34) = 4
Prototype
double cos(double x);
float cosf(float x);
double cosl(double x);
Return Value
The cosine of x. If an error occurs because x is too large, errno is set to ERANGE.
Special Results
value of x return value invalid? ±INFINITY NAN yesCompatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
The cosh functions calculate the hyperbolic cosine of x.
value of x return value invalid? ±INFINITY ±0.0 no
x | return value |
---|---|
+INFINITY | +INFINITY |
-INFINITY | +0.0 |
/* Example of exp */ #include <math.h> #include <stdio.h> #include <stdlib.h> int main() { double d; double result; printf("Enter a double:"); scanf("%lg", &d); result = exp(d); printf("\nexp(%lg) = %lg\n", d, result); return 0; }
x | return value |
---|---|
+INFINITY | +INFINITY |
-INFINITY | +0.0 |
Prototype
double expm1(double x);
float expm1f(float x);
long double expm1l(long double x);
Return Value
The value of ex-1
x | ex-1 |
---|---|
±0.0 | ±0.0 |
+INFINITY | +INFINITY |
-INFINITY | -1.0 |
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Prototype
double fabs(double x);
float fabsf(float x);
long double fabsl(long double x);
Return Value
The absolute value of x.
Special Results
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example of fabs */ #include <math.h> #include <stdio.h> #include <stdlib.h> void main() { double d; double result; printf("Enter a double:"); scanf("%lg", &d); result = fabs(d); printf("\nfabs(%lg) = %lg\n", d, result); }
Output
Enter a double:-2.34
fabs(-2.34) = 2.34
Prototype
double floor(double x);
float floorf(float x);
long double floorl(long double x);
Return Value
A floating-point value that represents x rounded down to the nearest integer.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
ceil
nearbyint
rint
rndtol
rndtonl
round
trunc
Example
/* Example of floor Also demonstrates floorl, floorf */ #include <stdlib.h> #include <stdio.h> #include <math.h> void main() { double d; printf("Enter a double: "); scanf("%lg", &d); printf("\nfloor(%g)=%g\n", d, floor (d)); }Output
Enter a double: 3.14 floor(3.14)= 3
Prototype
double fmod(double x, double y);
float fmodf(float x, float y);
long double fmodl(long double x, long double y);
Return Value
The value of x -i * y, where i is the number of times that y can be completely subtracted from x. The result has the same sign as x.
Special Results
value of x value of y return value invalid? ±0.0 not 0.0 ±0.0 no ±INFINITY anything NAN yes anything ±0.0 NAN yes !=± INFINITY ±INFINITY x no
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example for fmod Also demonstrates fmodf, fmodl */ #include <stdio.h> #include <stdlib.h> #include <math.h> void main() { double d1, d2, r; printf("Enter two doubles: "); scanf("%lg %lg", &d1, &d2); r = fmod(d1, d2); printf("fmod(%g, %g)=%g\n", d1, d2, r); }Output
Enter two doubles: 16 7
fmod (16, 7)=2
math.h
Prototype
double frexp(double x, int *exp);
float frexpf(float x, int *exp);
long double frexpl(long double x, int *exp);
Return Value
These functions return the mantissa. If x is 0, the functions return 0 for both the mantissa and the exponent. There is no error return.
Special Results
value of x return value *exp after?
±0.0 ±0.0 +0.0 ±INFINITY ±INFINITY ? NAN NAN ?
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example for frexp */ #include <stdio.h> #include <stdio.h> #include <math.h> void main() { int e; double d, r; printf("Enter a double: "); scanf("%lg", &d); r = frexp (d, &e); printf("%g, = %g * 2^%d.\n", d, r, e); }Output
Enter a double: 102
102, = 0.796875 * 2^7.
x | Return value | Range error? |
---|---|---|
0 | FP_ILOGB0 | yes |
±INFINITY | +INFINITY | no |
NAN | FP_ILOGBNAN | no |
Prototype
double ldexp(double n, int exp);
float ldexpf(float n, int exp);
long double ldexpl(long double n, int exp);
n * 2exp
Return Value
The value of n * 2exp.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example for ldexp */ #include <stdlib.h> #include <stdio.h> #include <math.h> void main() { int e; double d, r; printf("Enter a double and an int: "); scanf("%lg %d", &d, &e); r = ldexp (d, e); printf("%g = %g * 2^%d.\n\n", r, d, e); }Output
Enter a double and an int: 125 5
4000 = 125 * 2^ 5.
value of x | return value | divide by 0? | invalid? |
---|---|---|---|
±0.0 | -INFINITY | yes | no |
< 0.0 | NAN | no | yes |
+INFINITY | +INFINITY | no | no |
/* Example for log Also demonstrates logl */ #include <stdlib.h> #include <stdio.h> #include <math.h> void main() { double d; printf("Enter a double: "); scanf("%lg", &d); printf("\nlog(%g)=%g\n\n", d, log(d)); }
log(234)= 5.45532
value of x | return value | divide by 0? | invalid? |
---|---|---|---|
±0.0 | -INFINITY | yes | no |
< 0.0 | NAN | no | yes |
+INFINITY | +INFINITY | no | no |
1 <= x * FLT_RADIX-logb(x) < FLT_RADIX
x | Return value | Divide by 0? |
---|---|---|
±INFINITY | +INFINITY | no |
±0.0 | -INFINITY | yes |
Prototype
double log10(double x);
float log10f(float x);
long double log10l(long double x);
Return Value
The base-10 logarithm of x. If x < 0, a domain error is returned. If x == 0, a range error is returned.
value of x | return value | divide by 0? | invalid? |
---|---|---|---|
±0.0 | -INFINITY | yes | no |
< 0.0 | NAN | no | yes |
+INFINITY | +INFINITY | no | no |
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example for log10 */ #include <stdlib.h> #include <stdio.h> #include <math.h> int main() { double d; printf("Enter a double: "); scanf("%lg", &d); printf("\nlog10(%g)=%g\n\n", d, log10(d)); return 0; }Output
Enter a double: 234
log10(234)= 2.36922
Prototype
double log1p(double x);
float log1pf(float x);
Return Value
The natural logarithm of 1 + x.
x | log1p(x) | divide by 0? | invalid? |
---|---|---|---|
±0.0 | ±0.0 | no | no |
-1.0 | -INFINITY | yes | no |
<-1.0 | NAN | no | yes |
+INFINITY | -INFINITY | no | no |
See Also
Example
/* Example for log1p Also demonstrates loglpf */ #include <stdlib.h> #include <stdio.h> #include <math.h> void main() { double d; printf("Enter a double: "); scanf("%lg", &d); printf("\nlog1p(%g)=%g\n\n", d, log1p(d)); }Output
Enter a double: 1.234
log1p(1.234)= 0.803794
Prototype
int matherr(struct exception *except);
int _matherrl(struct _exceptionl *except);
A pointer to the exception structure will be passed to a user-supplied math error function when an error occurs. The exception structures, _exception and _exceptionl are defined in math.h. They have the following elements:
Return Value
These functions return 0 to indicate an error, non-zero for success.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
The other math functions
Prototype
double modf(double x, double *iptr);
float modff(float x, float *iptr);
long double modfl(long double x, long double *iptr);
Return Value
The signed fractional portion of x.
Special Results
value of x return value *iptr after ±INFINITY ±0.0 ±INFINITY
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
Example
/* Example for modf Also demonstrates modfl */ #include <stdlib.h> #include <stdio.h> #include <math.h> void main() { double d, frac, intr; printf("Enter a double: "); scanf("%lg", &d); frac = modf (d, &intr); printf("\nFor %g, the fractional part is %g,\nand the integral part is " "%g.\n", d, frac, intr); }Output
Enter a double: 123.456
For 123.456, the fractional part is 0.456,
and the integral part is 123.
Prototype
double nextafter(double x, double y);
float nextafterf(float x, float y)
long double nextafterl(long double x, long double y);
Return Value
If y is greater than x, the result will be the next largest floating-point value; if y is less than x, the result will be the next smallest value. If x and y are equal, the result is x. The FE_INEXACT and FE_OVERFLOW exceptions will be raised if x is finite and the function result is infinite. The FE_INEXACT and FE_UNDERFLOW exceptions will be raised if the function value is subnormal, and x is not equal to y.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
Example
/* Example for nextafter Also demonstrates nextafterf */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <fltpnt.h> void main() { double d1, d2, r; printf("Enter two doubles: "); scanf("%lg %lg", &d1, &d2); r = nextafter(d1, d2); printf("nextafter(%g, %g)=%. 16f\n", d1, d2, r); }Output
Enter two doubles: 1 2
nextafter(1, 2)= 1.0000000000000002
Prototype
double poly(double x, int deg, double coeff[]);
long double polyl(long double x, int deg, long double coeff[]);
(coeff[deg] * x + coeff [deg-1]) * x +...+ coeff[0].
Argument x is the base value; deg is the maximum degree, and coeff is an array containing the coefficients of the values.
The polyl function is the long double version of poly.
Return Value
Both functions return the calculated value of the polynomial.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
Example
/* Example for poly Also demonstrates polyl */ #include <stdio.h> #include <stdlib.h> #include <math.h> void main() { double coeff[4], x = 1.2, y; coeff[0] = 0.0; coeff[1] = 1.0; coeff[2] = 2.0; coeff[3] = 3.0; y = poly(x, 3, coeff); printf("poly(%g, 3, {%g, %g, %g, %g}) = %g\n", x, coeff[0], coeff[1], coeff[2], coeff[3], y); }Output
poly(1.2, 3, {0, 1, 2, 3}) = 9.264
Prototype
double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y);
Return Value
x raised to the power of y. If an overflow occurs, the pow functions set errno to ERANGE and return _HUGE_VAL or _LHUGE_VAL (if the return type is long double).
Special Results
value of x value of y return value div 0 inv anything ±0.0 1.0 no no |x| > 1. 0 +INFINITY +INFINITY no no |x| < 1. 0 +INFINITY +0.0 no no |x| > 1. 0 -INFINITY +0.0 no no |x| < 1. 0 -INFINITY +INFINITY no no +INFINITY y > 0.0 +INFINITY no no +INFINITY y < 0.0 +0.0 no no -INFINITY odd integer>0.0 -INFINITY no no -INFINITY >0.0,not odd +INFINITY no no integer -INFINITY odd integer<0.0 -0.0 no no -INFINITY <0.0, not odd +0.0 no no integer ±1.0 ±INFINITY NAN no yes <0.0 finite, NAN no yes nonintegral ±0.0 odd integer <0.0±INFINITY yes no ±0.0 <0.0, not odd +INFINITY yes no integer ±0.0 odd integer>0.0 ±0.0 no no ±0.0 >0.0, not odd +0.0 no no integer
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example for pow Also demonstrates powl */ #include <stdlib.h> #include <stdio.h> #include <math.h> void main() { double d1, d2; printf("Enter two doubles: "); scanf("%lg %lg", &d1, &d2); printf("\npow(%g, %g)=%g\n", d1, d2, pow (d1, d2)); }Output
Enter two doubles: 2 16
pow(2, 16)= 65536
value of x return value invalid? ±0.0 ±0.0 no ±INFINITY NAN yes
/* Example of sin() */ #include <stdlib.h> #include <stdio.h> #include <math.h> void main() { double d; printf("Enter a double: "); scanf("%lg", &d); printf("\nsin(%g)=%g\n", d, sin(d)); }
Enter a double: 100 sin(100)=-0.506366
Prototype
double sinh(double x);
float sinhf(float x);
long double sinhl(long double x);
Return Value
The hyperbolic sine of x. If the value of x is too large, errno is set to ERANGE.
x | return value | invalid? |
---|---|---|
±0.0 | ±0.0 | no |
±INFINITY | ±INFINITY | no |
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example of sinh Also demonstrates sinh */ #include <stdlib.h> #include <stdio.h> #include <math.h> void main() { double d; printf("Enter a double: "); scanf("%lg", &d); printf("\nsinh(%g)=%g\n", d, sinh (d)); }Output
Enter a double: 12
sinh(12)= 81377.4
x | return value | invalid? |
---|---|---|
0.0 | 0.0 | no |
<0.0 | NAN | yes |
NAN | NAN | yes |
+INFINITY | +INFINITY | no |
/* Example of sqrt */ #include <stdlib.h> #include <stdio.h> #include <math.h> int main() { double d; printf("Enter a double: "); scanf("%lg", &d); printf("\nsqrt(%g)=%g\n", d, sqrt(d)); return 0; }
sqrt(81)= 9
Prototype
double tan(double x);
float tanf(float x);
long double tanl(long double x);
Return Value
The tangent of x.
If x is too large, a partial loss of significance may occur. In this case, the tan functions set global variable errno to ERANGE and generate a _PLOSS error. If x is so large that significance is totally lost, tan functions print a _TLOSS error message to stderr, set errno to ERANGE, and return 0.
Special Results
value of x return value invalid? ±0.0 ±0.0 no ±INFINITY NAN yesCompatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example of tan Also demonstrates tanl */ #include <stdlib.h> #include <stdio.h> #include <math.h> void main() { double d; printf("Enter a double: "); scanf("%lg", &d); printf("\ntan(%g)=%g\n", d, tan (d)); }Output
Enter a double: 100
tan(100)=-0.587214
Prototype
double tanh(double x);
float tanhf(float x);
long double tanhl(long double x);
Return Value
The hyperbolic tangent of x.
Special Results
value of x return value invalid? ±0.0 ±0.0 no ±INFINITY ±1. 0 no
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example of tanh */ #include <stdlib.h> #include <stdio.h> #include <math.h> void main() { double d; printf("Enter a double: "); scanf("%lg", &d); printf("\ntanh(%g)=%g\n", d, tanh(d)); }
Enter a double: 3 tanh(3)= 0.995055
Prototype
double _cabs(struct _complex z);
long double _cabsl(struct _complexl z);
Synonym
Function: cabs, cabl
Argument: complex, complexl
Return Value
The absolute value of z. If an overflow occurs, these functions return HUGE_VAL, and set variable errno to ERANGE.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
Example
/* Example for cabs */ #include <math.h> #include <stdio.h> #include <stdlib.h> void main() { struct _complex z; double retval; z. x = 3.0; z. y = 1.0; retval = _cabs(z); printf("cabs of (%g,%gi) = %g", z. x, z. y, retval); }Output
cabs of (3,1i) = 3.16228
Prototype
float hypotf(float x, float y);
double hypot(double x, double y);
long double hypotl(long double x, long double y);
sqrt(x2 + y2)
x | y | return value | invalid? |
---|---|---|---|
x | +-0.0 | fabs(x) | no |
+-INFINITY | y | +INFINITY | no |
+-INFINITY | NAN | +INFINITY | no |
Note that hypot(x,y), hypot(y,x) and hypot(x,-y) are equivalent.
Compatibility
ANSI C99, DOS, Windows 3.x, Phar Lap, DOSX, Win32
See Also
cosh
sinh
tanh
ANSI C99 7.12.7.3, F.9.4.3
Example
/* Example for hypot */ #include <stdio.h> #include <math.h> void main() { double d1, d2; printf("Enter two doubles: "); scanf("%Lg %Lg", &d1, &d2); printf("\nhypot (%g, %g) = %g\n", d1, d2, hypot (d1, d2)); }Output
Enter two doubles: 5 5
hypot (5, 5) = 7.07107