math.h
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, log1pf | 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 |
fpclassify
- Header
- math.h
- Prototype
- int fpclassify(x);
- Description
-
This function, implemented as a macro, determines if a floating point
value belongs to a special class.
x's type is either float, double or long double.
The
following values can be compared to the result from fpclassify.
They classify floating point values and expand to a unique constant
expression of type int:
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
- See Also
- isfinite isinf isnan isnormal
isfinite, isinf, isnan, isnormal
- Header
- math.h
- Prototype
- int isfinite(x);
int isinf(x);
int isnan(x);
int isnormal(x);
- Description
-
Each of these takes an argument of type float, double, or long double;
and determines if the argument's value is of the classified type.
Function Test isfinite is normal, subnormal or zero isinf is infinity isnan is a NaN isnormal is not zero, infinity, subnormal, or NaN - Return Value
- Returns non-zero if a match, 0 if not.
- Compatibility
- C99 7.12.3
- See Also
- fpclassify
signbit
- Header
- math.h
- Prototype
- int signbit(x);
- Description
- Examines the sign bit of the floating-point value x (including NaNs, infinities, and zero). signbit is implemented as a macro, and x can be a float, double or long double.
- Return Value
- Non-zero if the sign bit is 1; zero if the sign bit is 0.
- Compatibility
- C99 7.12.3.6
acos
- Header
- math.h,
fltenv.h (Required for exception values) - Prototype
- double acos(double x);
float acosf(float x);
long double acosl(long double x);
- Description
- The acos functions calculate the principal value of the arc cosine of x.
- Return Value
- The arc cosine of x.
- Special Results
-
x return value invalid? >1.0 NAN yes <-1.0 NAN yes NAN NAN yes - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- 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
asin
- Header
- math.h
errno.h
fltenv.h (Required for exception values) - Prototype
- double asin(double x);
float asinf(float x);
long double asinl(long double x); - Description
- The asin functions calculate the principal value of the arcsine of x. asin calculates the arcsine of a double value; asinf calculates the arcsine of a floating-point value; and asinl calculates the arcsine of a long double value. The value of x must be between -1 and 1.
- 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
x return value invalid? ±0.0 ±0.0 no >1.0 NAN yes <-1.0 NAN yes - Compatibility
- 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
atan
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double atan(double x);
float atanf(float x);
long double atanl(long double x); - Description
- The atan functions calculate the arc tangent of x.
- Return Value
- The arc tangent of x. This is a value in the range of -π/2 to π/2.
- Special Results
x return value invalid? ±0.0 ±0.0 no ±INFINITY NAN yes - Compatibility
- 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
atan2
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double atan2(double y, double x);
float atan2f(float y, float x);
long double atan2l(long double y, long double x); - Description
- The atan2 functions calculate the arc tangent of y/x.
- Return Value
- The arc tangent of y/x. This is a value in the range -π to π.
If one argument is a NaN, that 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
y 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π/4 - Compatibility
- 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
cbrt
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double cbrt(double x);
float cbrtf(float x);
long double cbrtl(long double x); - Description
- The cbrt functions calculate the cube root of x.
- Return Value
- The cube root of x.
- Special Results
-
x return value invalid? ±0.0 ±0.0 no NAN NAN yes ±∞ ±∞ no - Compatibility
- C99 DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- exp expml pow sqrt
ceil
- Header
- math.h
- Prototype
- double ceil(double x);
float ceilf(float x);
long double ceill(long double x); - Description
- Returns the value of x rounded upward to the next integer (toward positive infinity.)
- 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
cos
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double cos(double x);
float cosf(float x);
double cosl(double x); - Description
- The cos functions calculate the cosine of x (measured in radians).
- Return Value
- The cosine of x. If an error occurs because x is too large, errno is set to ERANGE.
- Special Results
x return value invalid? ±INFINITY NAN yes - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- acos asin sin cosh
cosh
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double cosh(double x);
float coshf(float x);
long double coshl(long double x); - Description
- The cosh functions calculate the hyperbolic cosine of x.
- Return Value
- The hyperbolic sine of x. If the value of x is too large, errno is set to ERANGE.
- Special Results
value of x return value invalid? ±INFINITY ±0.0 no - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- sinh cos
exp
- Header
- math.h
- Prototype
- double exp(double x);
float expf(float x);
long double expl(long double x); - Description
- The exp functions calculate the value of the natural logarithm base (e) raised to the power of x.
- Return Value
- The value of ex. Otherwise, on overflow, returns HUGE_VAL and sets errno to ERANGE. On underflow, returns 0.
- Special Results
-
x return value +∞ +∞ -∞ +0.0 - Compatibility
- C99 DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- exp2 expm1 log log1p log10 pow sqrt
- Example
-
/* 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; }
- Output
Enter a double: 2.34 exp(2.34) = 10.3812
exp2
- Header
- math.h
- Prototype
- double exp2(double x);
float exp2f(float x);
long double exp2l(long double x); - Description
- The exp2 functions calculate the value of 2 raised to the power of x.
- Return Value
- The value of 2x. Otherwise, on overflow, returns HUGE_VAL and sets errno to ERANGE. On underflow, returns 0.
- Special Results
-
x return value +∞ +∞ -∞ +0.0 - Compatibility
- C99 DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- exp expm1 log log1p log10 pow sqrt
expm1
- Header
- math.h
- Prototype
- double expm1(double x);
float expm1f(float x);
long double expm1l(long double x); - Description
- Calculates the value of the natural logarithm base (e) raised to the power of x, minus 1. For very small x, expm1(x) is more accurate than exp(x) -1.
- Return Value
- The value of ex-1
- Special Results
-
x ex-1 ±0.0 ±0.0 +∞ +∞ -∞ -1.0 - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- exp log log1p log10 pow sqrt
fabs
- Header
- math.h
- Prototype
- double fabs(double x);
float fabsf(float x);
long double fabsl(long double x); - Description
- The fabs, fabsf, and fabsl functions calculate the absolute value of floating-point number x.
- Return Value
- The absolute value of x.
- Special Results
-
x return value ±0.0 +0.0 ±∞ +∞ - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- abs copysign signbit
- 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
floor
- Header
- math.h
- Prototype
- double floor(double x);
float floorf(float x);
long double floorl(long double x); - Description
- Returns the value of x rounded down to the nearest integer.
- 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 */ #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
fmod
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double fmod(double x, double y);
float fmodf(float x, float y);
long double fmodl(long double x, long double y); - Description
- These functions calculate the floating-point remainder of x/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
-
x 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
- div ldiv remainder remquo
- Example
/* Example for fmod */ #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
frexp
- Header
- math.h
- Prototype
- double frexp(double x, int *exp);
float frexpf(float x, int *exp);
long double frexpl(long double x, int *exp); - Description
- The frexp, frexpf, _frexpl, and frexpl functions break a floating-point number (x) into a mantisa (m) and an exponent (n), such that 0.5 <= |m| < 1.0 and x = m * 2n. The integer exponent n is stored at the location pointed to by 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
-
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
- ldexp
- 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.
hypot
- Header
- math.h
- Prototype
- float hypotf(float x, float y);
double hypot(double x, double y);
long double hypotl(long double x, long double y); - Description
- The hypot functions calculate the length of the
hypotenuse of a right-angled triangle with sides of length x and y.
The hypotenuse is the value of the square root of
the sums of the squares of x and y:
sqrt(x2 + y2)
- Return Value
- The hypotenuse of a right-angled triangle with sides x and y.
- Special Results
-
x y return value invalid? x +-0.0 fabs(x) no +-∞ y +∞ no +-∞ NAN +∞ 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
ilogb
- Header
- math.h
- Prototype
- int ilogb(double x);
int ilogbf(float x);
int ilogbl(long double x); - Description
- Extracts the exponent of x as a signed integral value. If x is not a special value, the result is the same as if logb was called instead and the result was cast to int.
- Return Value
- The signed exponent of the argument.
- Special Results
-
x Return value Range error? 0 FP_ILOGB0 yes ±∞ +∞ no NAN FP_ILOGBNAN no - Compatibility
- C99 7.12.6.5, Win32
- See Also
- logb loglp logpf log10 log
ldexp
- Header
- math.h
- Prototype
- double ldexp(double n, int exp);
float ldexpf(float n, int exp);
long double ldexpl(long double n, int exp); - Description
- Each function uses the following form to multiply a number by an
integral power of two:
n * 2exp
- Return Value
- The value of n * 2exp.
- Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- frexp
- 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.
log
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double log(double x);
float logf(float x);
long double logl(long double x); - Description
- The log functions calculate the natural logarithm of x.
- Return Value
- The natural logarithm of x. If x < 0, a domain error is returned. If x == 0, a range error is returned.
- Special Results
-
value of x return value divide by 0? invalid? ±0.0 -∞ yes no < 0.0 NAN no yes +∞ +∞ no no - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- loglp logpf log10
- Example
/* Example for log */ #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)); }
- Output
Enter a double: 234 log(234)= 5.45532
log2
- Header
- math.h
- Prototype
- double log2(double x);
float log2f(float x);
long double log2l(long double x); - Description
- The log2 functions calculate the base-2 logarithm of x, log2x.
- Return Value
- The natural logarithm of x. If x < 0, a domain error is returned. If x == 0, a range error is returned.
- Special Results
-
value of x return value divide by 0? invalid? ±0.0 -∞ yes no < 0.0 NAN no yes +∞ +∞ no no - Compatibility
- C99 Win32
- See Also
- loglp logpf log10 log
logb
- Header
- math.h
- Prototype
- double logb(double x);
float logbf(float x);
long double logbl(long double x); - Description
- Extracts the exponent of x as a signed integral value. If
x is subnormal, it is treated as if it were normalized. For
a positive, finite x:
1 <= x * FLT_RADIX-logb(x) < FLT_RADIX
- Return Value
- The signed exponent of the argument.
- Special Results
-
x Return value Divide by 0? ±∞ +∞ no ±0.0 -∞ yes - Compatibility
- C99 Win32
- See Also
- ilogb loglp logpf log10 log
log10
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double log10(double x);
float log10f(float x);
long double log10l(long double x); - Description
- The log10 functions calculate the base-10 logarithm of 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.
- Special Results
-
value of x return value divide by 0? invalid? ±0.0 -∞ yes no < 0.0 NAN no yes +∞ +∞ no no - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- log log1p
- 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
log1p, log1pf
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double log1p(double x);
float log1pf(float x); - Description
- The log1p and log1pf functions calculate the natural logarithm of 1 + x. For very small x, log1p(x) will be more accurate than log(1 + x).
- Return Value
- The natural logarithm of 1 + x.
- Special Results
-
x log1p(x) divide by 0? invalid? ±0.0 ±0.0 no no -1.0 -∞ yes no <-1.0 NAN no yes +∞ -∞ no no - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- log log10
- Example
/* Example for log1p */ #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
matherr, _matherrl
- Header
- math.h
- Prototype
- int matherr(struct exception *except);
int _matherrl(struct _exceptionl *except); - Description
- The matherr and _matherrl functions process errors that have
been generated by math functions. The math functions call a math
error function whenever an error occurs. Users can also provide their
own math error functions to implement special error handling. The
_matherrl is called for errors in long double math.
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:
The values for type are:Element Description int type Exception type (see the following table) char *name Function name where error occurred double arg1 arg2, Function arguments double retval Value returned by function Value Description _DOMAIN Argument domain error _SING Argument singularity _OVERFLOW Overflow range error _PLOSS Partial loss of significance _TLOSS Total loss of significance _UNDERFLOW Underflow range error - 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
modf
- Header
- math.h
- Prototype
- double modf(double x, double *iptr);
float modff(float x, float *iptr);
long double modfl(long double x, long double *iptr); - Description
- The modf functions break x into its integral and fraction parts. each of which has the same sign as x. The integral portion is stored in the double pointed to by iptr.
- Return Value
- The signed fractional portion of x.
- Special Results
-
x return value *iptr after ±INFINITY ±0.0 ±INFINITY - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- Example
/* Example for modf */ #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.
nextafter
- Header
- fltpnt.h
- Prototype
- double nextafter(double x, double y);
float nextafterf(float x, float y)
long double nextafterl(long double x, long double y); - Description
- Calculates the next representable value after x in the direction of 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 */ #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
poly
- Header
- math.h
- Prototype
- double poly(double x, int deg, double coeff[]);
long double polyl(long double x, int deg, long double coeff[]); - Description
- poly and polyl evaluate a polynomial of the form:
(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 */ #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
pow
- Header
- math.h
- Prototype
- double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y); - Description
- The pow functions calculate xy.
- 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
-
x y return value div 0 inv anything ±0.0 1.0 no no |x| > 1 +INFINITY +INFINITY no no |x| < 1 +INFINITY +0.0 no no |x| > 1 -INFINITY +0.0 no no |x| < 1 -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 integer +INFINITY no no -INFINITY odd integer<0.0 -0.0 no no -INFINITY <0.0, not odd integer +0.0 no no ±1.0 ±INFINITY NAN no yes <0.0 finite, nonintegral NAN no yes ±0.0 odd integer <0.0 ±INFINITY yes no ±0.0 <0.0, not odd integer +INFINITY yes no ±0.0 odd integer>0.0 ±0.0 no no ±0.0 >0.0, not odd integer +0.0 no no - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- exp log log1p log10 sqrt
- Example
/* Example for pow */ #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
sin
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double sin(double x);
float sinf(float x);
long double sinl(long double x); - Description
- The sin functions calculate the sine of x (measured in radians).
- Return Value
- The sine of x. If an error occurs because x is too large, errno is set to ERANGE.
- Special Results
-
x return value invalid? ±0.0 ±0.0 no ±INFINITY NAN yes - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- acos asin cos sinh
- Example
/* 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)); }
- Output
Enter a double: 100 sin(100)=-0.506366
sinh
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double sinh(double x);
float sinhf(float x);
long double sinhl(long double x); - Description
- The sinh functions calculate the hyperbolic sine of x.
- Return Value
- The hyperbolic sine of x. If the value of x is too large, errno is set to ERANGE.
- Special Results
-
x return value invalid? ±0.0 ±0.0 no ±∞ ±∞ no - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- cosh sin
- Example
/* Example of 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
sqrt
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double sqrt(double x);
float sqrtf(float x);
long double sqrtl(long double x); - Description
- The sqrt functions calculate the square root of x.
- Return Value
- The square root of x.
- Special Results
-
x return value invalid? 0.0 0.0 no <0.0 NAN yes NAN NAN yes +∞ +∞ no - Compatibility
- C99 DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- exp expml pow cbrt
- Example
/* 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; }
- Output
Enter a double: 81 sqrt(81)= 9
tan
- Header
- math.h
fltenv.h (Required for exception values) - Prototype
- double tan(double x);
float tanf(float x);
long double tanl(long double x); - Description
- The tan functions calculate the tangent of x (measured in radians).
- 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
-
x return value invalid? ±0.0 ±0.0 no ±INFINITY NAN yes - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- acos tanh
- Example
/* Example of tan */ #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
tanh
- Header
- math.h
- Prototype
- double tanh(double x);
float tanhf(float x);
long double tanhl(long double x); - Description
- The tanh functions calculate the hyperbolic tangent of x.
- Return Value
- The hyperbolic tangent of x.
- Special Results
-
x return value invalid? ±0.0 ±0.0 no ±INFINITY ±1.0 no - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- See Also
- acos tan
- 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)); }
- Output
Enter a double: 3 tanh(3)= 0.995055
_cabs, _cabsl
- Header
- math.h
- Prototype
- double _cabs(struct _complex z);
long double _cabsl(struct _complexl z); - Description
- The _cabs and _cabsl functions calculate the absolute value of the complex number stored in the z structure. This structure is composed of a real component x and an imaginary component y. In the _cabs function, x and y are double values; in the _cabsl function, x and y are long double values.
- 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
- abs fabs
- 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