Next: Mathematical Functions (math.h) [Contents][Index]
acos, acosf—arc cosineacosh, acoshf—inverse hyperbolic cosineasin, asinf—arc sineasinh, asinhf—inverse hyperbolic sineatan, atanf—arc tangentatan2, atan2f—arc tangent of y/xatanh, atanhf—inverse hyperbolic tangentjN, jNf, yN, yNf—Bessel functionscbrt, cbrtf—cube rootcopysign, copysignf—sign of y, magnitude of xcosh, coshf—hyperbolic cosineerf, erff, erfc, erfcf—error functionexp, expf—exponentialexp10, exp10f—exponential, base 10exp2, exp2f—exponential, base 2expm1, expm1f—exponential minus 1fabs, fabsf—absolute value (magnitude)fdim, fdimf—positive differencefloor, floorf, ceil, ceilf—floor and ceilingfma, fmaf—floating multiply addfmax, fmaxf—maximumfmin, fminf—minimumfmod, fmodf—floating-point remainder (modulo)frexp, frexpf—split floating-point numbergamma, gammaf, lgamma, lgammaf, gamma_r, gammaf_r, lgamma_r, lgammaf_r, tgamma, and tgammaf—logarithmic and plain gamma functionshypot, hypotf—distance from originilogb, ilogbf—get exponent of floating-point numberinfinity, infinityf—representation of infinityisgreater, isgreaterequal, isless, islessequal, islessgreater, and isunordered—comparison macrosfpclassify, isfinite, isinf, isnan, and isnormal—floating-point classification macros; finite, finitef, isinf, isinff, isnan, isnanf—test for exceptional numbersldexp, ldexpf—load exponentlog, logf—natural logarithmslog10, log10f—base 10 logarithmslog1p, log1pf—log of 1 + xlog2, log2f—base 2 logarithmlogb, logbf—get exponent of floating-point numberlrint, lrintf, llrint, llrintf—round to integerlround, lroundf, llround, llroundf—round to integer, to nearestmodf, modff—split fractional and integer partsnan, nanf—representation of “Not a Number”nearbyint, nearbyintf—round to integernextafter, nextafterf—get next numberpow, powf—x to the power ypow10, pow10f—base 10 power functionsremainder, remainderf—round and remainderremquo, remquof—remainder and part of quotientrint, rintf—round to integerround, roundf—round to integer, to nearestscalbn, scalbnf, scalbln, scalblnf—scale by power of FLT_RADIX (=2)signbit—Does floating-point number have negative sign?sin, sinf, cos, cosf—sine or cosinesinh, sinhf—hyperbolic sinesqrt, sqrtf—positive square roottan, tanf—tangenttanh, tanhf—hyperbolic tangenttrunc, truncf—round to integer, towards zerocabs, cabsf, cabsl—complex absolute-valuecacos, cacosf—complex arc cosinecacosh, cacoshf—complex arc hyperbolic cosinecarg, cargf—argument (phase angle)casin, casinf—complex arc sinecasinh, casinhf—complex arc hyperbolic sinecatan, catanf—complex arc tangentcatanh, catanhf—complex arc hyperbolic tangentccos, ccosf—complex cosineccosh, ccoshf—complex hyperbolic cosinecexp, cexpf—complex base-e exponentialcimag, cimagf, cimagl—imaginary partclog, clogf—complex base-e logarithmclog10, clog10f—complex base-10 logarithmconj, conjf—complex conjugatecpow, cpowf—complex powercproj, cprojf— Riemann sphere projectioncreal, crealf, creall—real partcsin, csinf—complex sinecsinh, csinhf—complex hyperbolic sinecsqrt, csqrtf—complex square rootctan, ctanf—complex tangentctanh, ctanf—complex hyperbolic tangentfeclearexcept—clear floating-point exceptionfegetenv—get current floating-point environmentfegetexceptflag—get floating-point status flagsfegetround—get current rounding directionfeholdexcept—save current floating-point environmentferaiseexcept—raise floating-point exceptionfesetenv—set current floating-point environmentfesetexceptflag—set floating-point status flagsfesetround—set current rounding directionfetestexcept—test floating-point exception flagsfeupdateenv—update current floating-point environmentlibmlibmNext: Mathematical Complex Functions (complex.h), Previous: LIBM, Up: LIBM [Contents][Index]
This chapter groups a wide variety of mathematical functions. Thecorresponding definitions and declarations are in math.h.The definition of HUGE_VAL from math.h is of particular interest.
double is defined asHUGE_VAL; this number is returned on overflow by many functions.The macro HUGE_VALF is a corresponding value for float.Alternative declarations of the mathematical functions, which exploitspecific machine capabilities to operate faster—but generally haveless error checking and may reflect additional limitations on somemachines—are available when you include fastmath.h instead ofmath.h.
acos, acosf—arc cosineacosh, acoshf—inverse hyperbolic cosineasin, asinf—arc sineasinh, asinhf—inverse hyperbolic sineatan, atanf—arc tangentatan2, atan2f—arc tangent of y/xatanh, atanhf—inverse hyperbolic tangentjN, jNf, yN, yNf—Bessel functionscbrt, cbrtf—cube rootcopysign, copysignf—sign of y, magnitude of xcosh, coshf—hyperbolic cosineerf, erff, erfc, erfcf—error functionexp, expf—exponentialexp10, exp10f—exponential, base 10exp2, exp2f—exponential, base 2expm1, expm1f—exponential minus 1fabs, fabsf—absolute value (magnitude)fdim, fdimf—positive differencefloor, floorf, ceil, ceilf—floor and ceilingfma, fmaf—floating multiply addfmax, fmaxf—maximumfmin, fminf—minimumfmod, fmodf—floating-point remainder (modulo)frexp, frexpf—split floating-point numbergamma, gammaf, lgamma, lgammaf, gamma_r, gammaf_r, lgamma_r, lgammaf_r, tgamma, and tgammaf—logarithmic and plain gamma functionshypot, hypotf—distance from originilogb, ilogbf—get exponent of floating-point numberinfinity, infinityf—representation of infinityisgreater, isgreaterequal, isless, islessequal, islessgreater, and isunordered—comparison macrosfpclassify, isfinite, isinf, isnan, and isnormal—floating-point classification macros; finite, finitef, isinf, isinff, isnan, isnanf—test for exceptional numbersldexp, ldexpf—load exponentlog, logf—natural logarithmslog10, log10f—base 10 logarithmslog1p, log1pf—log of 1 + xlog2, log2f—base 2 logarithmlogb, logbf—get exponent of floating-point numberlrint, lrintf, llrint, llrintf—round to integerlround, lroundf, llround, llroundf—round to integer, to nearestmodf, modff—split fractional and integer partsnan, nanf—representation of “Not a Number”nearbyint, nearbyintf—round to integernextafter, nextafterf—get next numberpow, powf—x to the power ypow10, pow10f—base 10 power functionsremainder, remainderf—round and remainderremquo, remquof—remainder and part of quotientrint, rintf—round to integerround, roundf—round to integer, to nearestscalbn, scalbnf, scalbln, scalblnf—scale by power of FLT_RADIX (=2)signbit—Does floating-point number have negative sign?sin, sinf, cos, cosf—sine or cosinesinh, sinhf—hyperbolic sinesqrt, sqrtf—positive square roottan, tanf—tangenttanh, tanhf—hyperbolic tangenttrunc, truncf—round to integer, towards zeroThere are two different versions of the math library routines: IEEEand POSIX. The version may be selected at runtime bysetting the global variable _LIB_VERSION, defined inmath.h. It may be set to one of the following constants definedin math.h: _IEEE_ or _POSIX_.The _LIB_VERSION variable is not specific to anythread, and changing it will affect all threads.
The versions of the library differ only in the setting of errno.
In IEEE mode, errno is never set.
In POSIX mode, errno is set correctly.
The library is set to IEEE mode by default.
The majority of the floating-point math functions are writtenso as to produce the floating-point exceptions (e.g. "invalid","divide-by-zero") as required by the C and POSIX standards, forfloating-point implementations that support them. Newlib does not providethe floating-point exception access routines defined in the standardsfor fenv.h, though, which is why they are considered unsupported. It ismentioned in case you have separately-provided access routines so thatyou are aware that they can be caused.
Most of the individual function descriptions describe the standards to whicheach function complies. However, these descriptions are mostly out of date,having been written before C99 was released. One of these days we’ll getaround to updating the rest of them. (If you’d like to help, please let usknow.)
“C99” refers to ISO/IEC 9899:1999, “Programming languages–C”.“POSIX” refers to IEEE Standard 1003.1. POSIX® is aregistered trademark of The IEEE.
Next: acosh, acoshf—inverse hyperbolic cosine, Up: Mathematical Functions (math.h) [Contents][Index]
acos, acosf—arc cosineSynopsis
#include <math.h>double acos(double x);float acosf(float x);
Description
acos computes the inverse cosine (arc cosine) of the input value.Arguments to acos must be in the range -1 to 1.
acosf is identical to acos, except that it performsits calculations on floats.
Returnsacos and acosf return values in radians, in the range of 0 to pi.
If x is not between -1 and 1, the returned value is NaN(not a number), and the global variable errno is set to EDOM.
Next: asin, asinf—arc sine, Previous: acos, acosf—arc cosine, Up: Mathematical Functions (math.h) [Contents][Index]
acosh, acoshf—inverse hyperbolic cosineSynopsis
#include <math.h>double acosh(double x);float acoshf(float x);
Descriptionacosh calculates the inverse hyperbolic cosine of x.acosh is defined as
log(x + sqrt(x*x-1))
x must be a number greater than or equal to 1.
acoshf is identical, other than taking and returning floats.
Returnsacosh and acoshf return the calculated value. If xless than 1, the return value is NaN and errno is set to EDOM.
Portability
Neither acosh nor acoshf are ANSI C. They are not recommendedfor portable programs.
Next: asinh, asinhf—inverse hyperbolic sine, Previous: acosh, acoshf—inverse hyperbolic cosine, Up: Mathematical Functions (math.h) [Contents][Index]
asin, asinf—arc sineSynopsis
#include <math.h>double asin(double x);float asinf(float x);
Description
asin computes the inverse sine (arc sine) of the argument x.Arguments to asin must be in the range -1 to 1.
asinf is identical to asin, other than taking andreturning floats.
Returnsasin returns values in radians, in the range of -pi/2 to pi/2.
If x is not in the range -1 to 1, asin and asinfreturn NaN (not a number), and the global variable errno is set toEDOM.
Next: atan, atanf—arc tangent, Previous: asin, asinf—arc sine, Up: Mathematical Functions (math.h) [Contents][Index]
asinh, asinhf—inverse hyperbolic sineSynopsis
#include <math.h>double asinh(double x);float asinhf(float x);
Descriptionasinh calculates the inverse hyperbolic sine of x.asinh is defined as
sgn(x) * log(abs(x) + sqrt(1+x*x))
asinhf is identical, other than taking and returning floats.
Returnsasinh and asinhf return the calculated value.
Portability
Neither asinh nor asinhf are ANSI C.
Next: atan2, atan2f—arc tangent of y/x, Previous: asinh, asinhf—inverse hyperbolic sine, Up: Mathematical Functions (math.h) [Contents][Index]
atan, atanf—arc tangentSynopsis
#include <math.h>double atan(double x);float atanf(float x);
Description
atan computes the inverse tangent (arc tangent) of the input value.
atanf is identical to atan, save that it operates on floats.
Returnsatan returns a value in radians, in the range of -pi/2 to pi/2.
Portabilityatan is ANSI C. atanf is an extension.
Next: atanh, atanhf—inverse hyperbolic tangent, Previous: atan, atanf—arc tangent, Up: Mathematical Functions (math.h) [Contents][Index]
atan2, atan2f—arc tangent of y/xSynopsis
#include <math.h>double atan2(double y,double x);float atan2f(float y,float x);
Description
atan2 computes the inverse tangent (arc tangent) of y/x. atan2 produces the correct result even for angles nearpi/2 or -pi/2(that is, when x is near 0).
atan2f is identical to atan2, save that it takes and returnsfloat.
Returnsatan2 and atan2f return a value in radians, in the range of-pi to pi.
Portabilityatan2 is ANSI C. atan2f is an extension.
Next: jN, jNf, yN, yNf—Bessel functions, Previous: atan2, atan2f—arc tangent of y/x, Up: Mathematical Functions (math.h) [Contents][Index]
atanh, atanhf—inverse hyperbolic tangentSynopsis
#include <math.h>double atanh(double x);float atanhf(float x);
Descriptionatanh calculates the inverse hyperbolic tangent of x.
atanhf is identical, other than taking and returningfloat values.
Returnsatanh and atanhf return the calculated value.
If
x|
is greater than 1, the global errno is set to EDOM andthe result is a NaN. A DOMAIN error is reported.
If
x|
is 1, the global errno is set to EDOM; and the result isinfinity with the same sign as x. A SING error is reported.
Portability
Neither atanh nor atanhf are ANSI C.
Next: cbrt, cbrtf—cube root, Previous: atanh, atanhf—inverse hyperbolic tangent, Up: Mathematical Functions (math.h) [Contents][Index]
jN, jNf, yN, yNf—Bessel functionsSynopsis
#include <math.h>double j0(double x);float j0f(float x);double j1(double x);float j1f(float x);double jn(int n, double x);float jnf(int n, float x);double y0(double x);float y0f(float x);double y1(double x);float y1f(float x);double yn(int n, double x);float ynf(int n, float x);
Description
The Bessel functions are a family of functions that solve thedifferential equation
2 2 2 x y'' + xy' + (x - p )y = 0
These functions have many applications in engineering and physics.
jn calculates the Bessel function of the first kind of ordern. j0 and j1 are special cases for order 0 and order1 respectively.
Similarly, yn calculates the Bessel function of the second kind oforder n, and y0 and y1 are special cases for order 0 and1.
jnf, j0f, j1f, ynf, y0f, and y1f perform thesame calculations, but on float rather than double values.
Returns
The value of each Bessel function at x is returned.
Portability
None of the Bessel functions are in ANSI C.
Next: copysign, copysignf—sign of y, magnitude of x, Previous: jN, jNf, yN, yNf—Bessel functions, Up: Mathematical Functions (math.h) [Contents][Index]
cbrt, cbrtf—cube rootSynopsis
#include <math.h>double cbrt(double x);float cbrtf(float x);
Descriptioncbrt computes the cube root of the argument.
Returns
The cube root is returned.
Portabilitycbrt is in System V release 4. cbrtf is an extension.
Next: cosh, coshf—hyperbolic cosine, Previous: cbrt, cbrtf—cube root, Up: Mathematical Functions (math.h) [Contents][Index]
copysign, copysignf—sign of y, magnitude of xSynopsis
#include <math.h>double copysign (double x, double y);float copysignf (float x, float y);
Descriptioncopysign constructs a number with the magnitude (absolute value)of its first argument, x, and the sign of its second argument,y.
copysignf does the same thing; the two functions differ only inthe type of their arguments and result.
Returnscopysign returns a double with the magnitude ofx and the sign of y.copysignf returns a float with the magnitude ofx and the sign of y.
Portabilitycopysign is not required by either ANSI C or the System V InterfaceDefinition (Issue 2).
Next: erf, erff, erfc, erfcf—error function, Previous: copysign, copysignf—sign of y, magnitude of x, Up: Mathematical Functions (math.h) [Contents][Index]
cosh, coshf—hyperbolic cosineSynopsis
#include <math.h>double cosh(double x);float coshf(float x);
Description
cosh computes the hyperbolic cosine of the argument x.cosh(x) is defined as
(exp(x) + exp(-x))/2
Angles are specified in radians. coshf is identical, save that it takes and returns float.
Returns
The computed value is returned. When the correct value would createan overflow, cosh returns the value HUGE_VAL with theappropriate sign, and the global value errno is set to ERANGE.
Portabilitycosh is ANSI. coshf is an extension.
Next: exp, expf—exponential, Previous: cosh, coshf—hyperbolic cosine, Up: Mathematical Functions (math.h) [Contents][Index]
erf, erff, erfc, erfcf—error functionSynopsis
#include <math.h>double erf(double x);float erff(float x);double erfc(double x);float erfcf(float x);
Descriptionerf calculates an approximation to the “error function”,which estimates the probability that an observation will fall withinx standard deviations of the mean (assuming a normaldistribution).
erfc calculates the complementary probability; that is,erfc(x) is 1 - erf(x). erfc is computed directly,so that you can use it to avoid the loss of precision that wouldresult from subtracting large probabilities (on large x) from 1.
erff and erfcf differ from erf and erfc only in theargument and result types.
Returns
For positive arguments, erf and all its variants return aprobability—a number between 0 and 1.
Portability
None of the variants of erf are ANSI C.
Next: exp10, exp10f—exponential, base 10, Previous: erf, erff, erfc, erfcf—error function, Up: Mathematical Functions (math.h) [Contents][Index]
exp, expf—exponentialSynopsis
#include <math.h>double exp(double x);float expf(float x);
Descriptionexp and expf calculate the exponential of x, that is,e raised to the power x (where eis the base of the natural system of logarithms, approximately 2.71828).
Returns
On success, exp and expf return the calculated value.If the result underflows, the returned value is 0. If theresult overflows, the returned value is HUGE_VAL. Ineither case, errno is set to ERANGE.
Portabilityexp is ANSI C. expf is an extension.
Next: exp2, exp2f—exponential, base 2, Previous: exp, expf—exponential, Up: Mathematical Functions (math.h) [Contents][Index]
exp10, exp10f—exponential, base 10Synopsis
#include <math.h>double exp10(double x);float exp10f(float x);
Descriptionexp10 and exp10f calculate 10 ^ x, that is,10 raised to the power x.
Returns
On success, exp10 and exp10f return the calculated value.If the result underflows, the returned value is 0. If theresult overflows, the returned value is HUGE_VAL. Ineither case, errno is set to ERANGE.
Portabilityexp10 and exp10f are GNU extensions.
Next: expm1, expm1f—exponential minus 1, Previous: exp10, exp10f—exponential, base 10, Up: Mathematical Functions (math.h) [Contents][Index]
exp2, exp2f—exponential, base 2Synopsis
#include <math.h>double exp2(double x);float exp2f(float x);
Descriptionexp2 and exp2f calculate 2 ^ x, that is,2 raised to the power x.
Returns
On success, exp2 and exp2f return the calculated value.If the result underflows, the returned value is 0. If theresult overflows, the returned value is HUGE_VAL. Ineither case, errno is set to ERANGE.
Portability
ANSI C, POSIX.
Next: fabs, fabsf—absolute value (magnitude), Previous: exp2, exp2f—exponential, base 2, Up: Mathematical Functions (math.h) [Contents][Index]
expm1, expm1f—exponential minus 1Synopsis
#include <math.h>double expm1(double x);float expm1f(float x);
Descriptionexpm1 and expm1f calculate the exponential of xand subtract 1, that is,e raised to the power x minus 1 (where eis the base of the natural system of logarithms, approximately2.71828). The result is accurate even for small values ofx, where using exp(x)-1 would lose manysignificant digits.
Returns
e raised to the power x, minus 1.
Portability
Neither expm1 nor expm1f is required by ANSI C or bythe System V Interface Definition (Issue 2).
Next: fdim, fdimf—positive difference, Previous: expm1, expm1f—exponential minus 1, Up: Mathematical Functions (math.h) [Contents][Index]
fabs, fabsf—absolute value (magnitude)Synopsis
#include <math.h>double fabs(double x);float fabsf(float x);
Descriptionfabs and fabsf calculatethe absolute value (magnitude) of the argument x, by directmanipulation of the bit representation of x.
Returns
The calculated value is returned. No errors are detected.
Portabilityfabs is ANSI.fabsf is an extension.
Next: floor, floorf, ceil, ceilf—floor and ceiling, Previous: fabs, fabsf—absolute value (magnitude), Up: Mathematical Functions (math.h) [Contents][Index]
fdim, fdimf—positive differenceSynopsis
#include <math.h>double fdim(double x, double y);float fdimf(float x, float y);
Description
The fdim functions determine the positive difference between theirarguments, returning:
x - yif x > y, or
+0 if x <= y, or
NAN if either argument is NAN.
A range error may occur.
Returns
The fdim functions return the positive difference value.
Portability
ANSI C, POSIX.
Next: fma, fmaf—floating multiply add, Previous: fdim, fdimf—positive difference, Up: Mathematical Functions (math.h) [Contents][Index]
floor, floorf, ceil, ceilf—floor and ceilingSynopsis
#include <math.h>double floor(double x);float floorf(float x);double ceil(double x);float ceilf(float x);
Descriptionfloor and floorf findthe nearest integer less than or equal to x.ceil and ceilf findthe nearest integer greater than or equal to x.
Returnsfloor and ceil return the integer result as a double.floorf and ceilf return the integer result as a float.
Portabilityfloor and ceil are ANSI.floorf and ceilf are extensions.
Next: fmax, fmaxf—maximum, Previous: floor, floorf, ceil, ceilf—floor and ceiling, Up: Mathematical Functions (math.h) [Contents][Index]
fma, fmaf—floating multiply addSynopsis
#include <math.h>double fma(double x, double y, double z);float fmaf(float x, float y, float z);
Description
The fma functions compute (x * y) + z, rounded as one ternaryoperation: they compute the value (as if) to infinite precision and round onceto the result format, according to the rounding mode characterized by the valueof FLT_ROUNDS. That is, they are supposed to do this: see below.
Returns
The fma functions return (x * y) + z, rounded as one ternaryoperation.
Bugs
This implementation does not provide the function that it should, purelyreturning "(x * y) + z;" with no attempt at all to provide thesimulated infinite precision intermediates which are required. DO NOT USE THEM.
If double has enough more precision than float, then fmaf should providethe expected numeric results, as it does use double for the calculation. Butsince this is not the case for all platforms, this manual cannot determineif it is so for your case.
Portability
ANSI C, POSIX.
Next: fmin, fminf—minimum, Previous: fma, fmaf—floating multiply add, Up: Mathematical Functions (math.h) [Contents][Index]
fmax, fmaxf—maximumSynopsis
#include <math.h>double fmax(double x, double y);float fmaxf(float x, float y);
Description
The fmax functions determine the maximum numeric value of their arguments.NaN arguments are treated as missing data: if one argument is a NaN and theother numeric, then the fmax functions choose the numeric value.
Returns
The fmax functions return the maximum numeric value of their arguments.
Portability
ANSI C, POSIX.
Next: fmod, fmodf—floating-point remainder (modulo), Previous: fmax, fmaxf—maximum, Up: Mathematical Functions (math.h) [Contents][Index]
fmin, fminf—minimumSynopsis
#include <math.h>double fmin(double x, double y);float fminf(float x, float y);
Description
The fmin functions determine the minimum numeric value of their arguments.NaN arguments are treated as missing data: if one argument is a NaN and theother numeric, then the fmin functions choose the numeric value.
Returns
The fmin functions return the minimum numeric value of their arguments.
Portability
ANSI C, POSIX.
Next: frexp, frexpf—split floating-point number, Previous: fmin, fminf—minimum, Up: Mathematical Functions (math.h) [Contents][Index]
fmod, fmodf—floating-point remainder (modulo)Synopsis
#include <math.h>double fmod(double x, double y);float fmodf(float x, float y);
Description
The fmod and fmodf functions compute the floating-pointremainder of x/y (x modulo y).
Returns
The fmod function returns the value x-i*y,for the largest integer i such that, if y is nonzero, theresult has the same sign as x and magnitude less than themagnitude of y.
fmod(x,0) returns NaN, and sets errno to EDOM.
Portabilityfmod is ANSI C. fmodf is an extension.
Next: gamma, gammaf, lgamma, lgammaf, gamma_r, gammaf_r, lgamma_r, lgammaf_r, tgamma, and tgammaf—logarithmic and plain gamma functions, Previous: fmod, fmodf—floating-point remainder (modulo), Up: Mathematical Functions (math.h) [Contents][Index]
frexp, frexpf—split floating-point numberSynopsis
#include <math.h>double frexp(double val, int *exp);float frexpf(float val, int *exp);
Description
All nonzero, normal numbers can be described as m * 2**p.frexp represents the double val as a mantissa mand a power of two p. The resulting mantissa will alwaysbe greater than or equal to 0.5, and less than 1.0 (aslong as val is nonzero). The power of two will be storedin *exp.
m and p are calculated so thatval is m times 2 to the power p.
frexpf is identical, other than taking and returningfloats rather than doubles.
Returnsfrexp returns the mantissa m. If val is 0, infinity,or Nan, frexp will set *exp to 0 and return val.
Portabilityfrexp is ANSI.frexpf is an extension.
Next: hypot, hypotf—distance from origin, Previous: frexp, frexpf—split floating-point number, Up: Mathematical Functions (math.h) [Contents][Index]
gamma, gammaf, lgamma, lgammaf, gamma_r, gammaf_r, lgamma_r, lgammaf_r, tgamma, and tgammaf—logarithmic and plain gamma functionsSynopsis
#include <math.h>double gamma(double x);float gammaf(float x);double lgamma(double x);float lgammaf(float x);double gamma_r(double x, int *signgamp);float gammaf_r(float x, int *signgamp);double lgamma_r(double x, int *signgamp);float lgammaf_r(float x, int *signgamp);double tgamma(double x);float tgammaf(float x);
Descriptiongamma calculatesthe natural logarithm of the gamma function of x. The gamma function(exp(gamma(x))) is a generalization of factorial, and retainsthe property thatexp(gamma(N)) is equivalent to N*exp(gamma(N-1)).Accordingly, the results of the gamma function itself grow veryquickly. gamma is defined asthe natural log of the gamma function, rather than the gamma functionitself,to extend the useful range of results representable.
The sign of the result is returned in the global variable signgam,which is declared in math.h.
gammaf performs the same calculation as gamma, but uses andreturns float values.
lgamma and lgammaf are alternate names for gamma andgammaf. The use of lgamma instead of gamma is a reminderthat these functions compute the log of the gamma function, ratherthan the gamma function itself.
The functions gamma_r, gammaf_r, lgamma_r, andlgammaf_r are just like gamma, gammaf, lgamma, andlgammaf, respectively, but take an additional argument. Thisadditional argument is a pointer to an integer. This additionalargument is used to return the sign of the result, and the globalvariable signgam is not used. These functions may be used forreentrant calls (but they will still set the global variable errnoif an error occurs).
tgamma and tgammaf are the "true gamma" functions, returningthe gamma function of x–without a logarithm.(They are apparently so named because of the prior existence of the old,poorly-named gamma functions which returned the log of gamma upthrough BSD 4.2.)
Returns
Normally, the computed result is returned.
When x is a nonpositive integer, gamma returns HUGE_VALand errno is set to EDOM. If the result overflows, gammareturns HUGE_VAL and errno is set to ERANGE.
Portability
Neither gamma nor gammaf is ANSI C. It is better not to use eitherof these; use lgamma or tgamma instead.lgamma, lgammaf, tgamma, and tgammaf are nominally C standardin terms of the base return values, although the signgam global forlgamma is not standard.
Next: ilogb, ilogbf—get exponent of floating-point number, Previous: gamma, gammaf, lgamma, lgammaf, gamma_r, gammaf_r, lgamma_r, lgammaf_r, tgamma, and tgammaf—logarithmic and plain gamma functions, Up: Mathematical Functions (math.h) [Contents][Index]
hypot, hypotf—distance from originSynopsis
#include <math.h>double hypot(double x, double y);float hypotf(float x, float y);
Descriptionhypot calculates the Euclidean distancesqrt(x*x + y*y)between the origin (0,0) and a point represented by theCartesian coordinates (x,y). hypotf differs onlyin the type of its arguments and result.
Returns
Normally, the distance value is returned. On overflow,hypot returns HUGE_VAL and sets errno toERANGE.
Portabilityhypot and hypotf are not ANSI C.
Next: infinity, infinityf—representation of infinity, Previous: hypot, hypotf—distance from origin, Up: Mathematical Functions (math.h) [Contents][Index]
ilogb, ilogbf—get exponent of floating-point numberSynopsis
#include <math.h>int ilogb(double val);int ilogbf(float val);
Description
All nonzero, normal numbers can be described as m *2**p. ilogb and ilogbf examine the argumentval, and return p. The functions frexp andfrexpf are similar to ilogb and ilogbf, but alsoreturn m.
Returns
ilogb and ilogbf return the power of two used to form thefloating-point argument.If val is 0, they return FP_ILOGB0.If val is infinite, they return INT_MAX.If val is NaN, they return FP_ILOGBNAN.(FP_ILOGB0 and FP_ILOGBNAN are defined in math.h, but in turn aredefined as INT_MIN or INT_MAX from limits.h. The value of FP_ILOGB0 may beeither INT_MIN or -INT_MAX. The value of FP_ILOGBNAN may be either INT_MAX orINT_MIN.)
Portability
C99, POSIX
Next: isgreater, isgreaterequal, isless, islessequal, islessgreater, and isunordered—comparison macros, Previous: ilogb, ilogbf—get exponent of floating-point number, Up: Mathematical Functions (math.h) [Contents][Index]
infinity, infinityf—representation of infinitySynopsis
#include <math.h>double infinity(void);float infinityf(void);
Descriptioninfinity and infinityf return the special number IEEEinfinity in double- and single-precision arithmeticrespectively.
Portabilityinfinity and infinityf are neither standard C nor POSIX. C andPOSIX require macros HUGE_VAL and HUGE_VALF to be defined in math.h, whichNewlib defines to be infinities corresponding to these archaic infinity()and infinityf() functions in floating-point implementations which do haveinfinities.
Next: fpclassify, isfinite, isinf, isnan, and isnormal—floating-point classification macros; finite, finitef, isinf, isinff, isnan, isnanf—test for exceptional numbers, Previous: infinity, infinityf—representation of infinity, Up: Mathematical Functions (math.h) [Contents][Index]
isgreater, isgreaterequal, isless, islessequal, islessgreater, and isunordered—comparison macrosSynopsis
#include <math.h>int isgreater(real-floating x, real-floating y);int isgreaterequal(real-floating x, real-floating y);int isless(real-floating x, real-floating y);int islessequal(real-floating x, real-floating y);int islessgreater(real-floating x, real-floating y);int isunordered(real-floating x, real-floating y);
Descriptionisgreater, isgreaterequal, isless, islessequal,islessgreater, and isunordered are macros defined for use incomparing floating-point numbers without raising any floating-pointexceptions.
The relational operators (i.e. <, >, <=, and >=) support the usual mathematicalrelationships between numeric values. For any ordered pair of numericvalues exactly one of the relationships–less, greater, and equal–istrue. Relational operators may raise the "invalid" floating-pointexception when argument values are NaNs. For a NaN and a numeric value, orfor two NaNs, just the unordered relationship is true (i.e., if one or bothof the arguments a NaN, the relationship is called unordered). The specifiedmacros are quiet (non floating-point exception raising) versions of therelational operators, and other comparison macros that facilitate writingefficient code that accounts for NaNs without suffering the "invalid"floating-point exception. In the synopses shown, "real-floating" indicatesthat the argument is an expression of real floating type.
Please note that saying that the macros do not raise floating-pointexceptions, it is referring to the function that they are performing. Itis certainly possible to give them an expression which causes an exception.For example:
NaN < 1.0causes an "invalid" exception,
isless(NaN, 1.0)does not, and
isless(NaN*0., 1.0)causes an exception due to the "NaN*0.", but not from theresultant reduced comparison of isless(NaN, 1.0).
Returns
No floating-point exceptions are raised for any of the macros.
The isgreater macro returns the value of (x) > (y).
The isgreaterequal macro returns the value of (x) >= (y).
The isless macro returns the value of (x) < (y).
The islessequal macro returns the value of (x) <= (y).
The islessgreater macro returns the value of (x) < (y) || (x) > (y).
The isunordered macro returns 1 if either of its arguments is NaN and 0 otherwise.
Portability
C99, POSIX.
Next: ldexp, ldexpf—load exponent, Previous: isgreater, isgreaterequal, isless, islessequal, islessgreater, and isunordered—comparison macros, Up: Mathematical Functions (math.h) [Contents][Index]
fpclassify, isfinite, isinf, isnan, and isnormal—floating-point classification macros; finite, finitef, isinf, isinff, isnan, isnanf—test for exceptional numbersSynopsis
[C99 standard macros:]#include <math.h>int fpclassify(real-floating x);int isfinite(real-floating x);int isinf(real-floating x);int isnan(real-floating x);int isnormal(real-floating x);[Archaic SUSv2 functions:]#include <math.h>int isnan(double arg);int isinf(double arg);int finite(double arg);int isnanf(float arg);int isinff(float arg);int finitef(float arg);
Descriptionfpclassify, isfinite, isinf, isnan, and isnormal are macrosdefined for use in classifying floating-point numbers. This is a help becauseof special "values" like NaN and infinities. In the synopses shown,"real-floating" indicates that the argument is an expression of real floatingtype. These function-like macros are C99 and POSIX-compliant, and should beused instead of the now-archaic SUSv2 functions.
The fpclassify macro classifies its argument value as NaN, infinite, normal,subnormal, zero, or into another implementation-defined category. First, anargument represented in a format wider than its semantic type is converted toits semantic type. Then classification is based on the type of the argument.The fpclassify macro returns the value of the number classification macroappropriate to the value of its argument:
FP_INFINITEx is either plus or minus infinity;
FP_NANx is "Not A Number" (plus or minus);
FP_NORMALx is a "normal" number (i.e. is none of the other special forms);
FP_SUBNORMALx is too small be stored as a regular normalized number (i.e. loss of precision is likely); or
FP_ZEROx is 0 (either plus or minus).
The "is" set of macros provide a useful set of shorthand ways forclassifying floating-point numbers, providing the following equivalentrelations:
isfinite(x)returns non-zero if x is finite. (It is equivalent to(fpclassify(x) != FP_INFINITE && fpclassify(x) != FP_NAN).)
isinf(x)returns non-zero if x is infinite. (It is equivalent to(fpclassify(x) == FP_INFINITE).)
isnan(x)returns non-zero if x is NaN. (It is equivalent to(fpclassify(x) == FP_NAN).)
isnormal(x)returns non-zero if x is normal. (It is equivalent to(fpclassify(x) == FP_NORMAL).)
The archaic SUSv2 functions provide information on the floating-pointargument supplied.
There are five major number formats ("exponent" referring to thebiased exponent in the binary-encoded number):
zeroA number which contains all zero bits, excluding the sign bit.
subnormalA number with a zero exponent but a nonzero fraction.
normalA number with an exponent and a fraction.
infinityA number with an all 1’s exponent and a zero fraction.
NANA number with an all 1’s exponent and a nonzero fraction.
isnan returns 1 if the argument is a nan. isinfreturns 1 if the argument is infinity. finite returns 1 if theargument is zero, subnormal or normal.The isnanf, isinff and finitef functions perform the sameoperations as their isnan, isinf and finitecounterparts, but on single-precision floating-point numbers.
It should be noted that the C99 standard dictates that isnanand isinf are macros that operate on multiple types offloating-point. The SUSv2 standard declares isnan asa function taking double. Newlib has decided to declarethem both as functions and as macros in math.h tomaintain backward compatibility.
Returns
The fpclassify macro returns the value corresponding to the appropriate FP_ macro.
The isfinite macro returns nonzero if x is finite, else 0.
The isinf macro returns nonzero if x is infinite, else 0.
The isnan macro returns nonzero if x is an NaN, else 0.
The isnormal macro returns nonzero if x has a normal value, else 0.
Portability
math.h macros are C99, POSIX.1-2001.
The functions originate from BSD; isnan was listed in the X/OpenPortability Guide and Single Unix Specification, but was dropped whenthe macro was standardized in POSIX.1-2001.
Next: log, logf—natural logarithms, Previous: fpclassify, isfinite, isinf, isnan, and isnormal—floating-point classification macros; finite, finitef, isinf, isinff, isnan, isnanf—test for exceptional numbers, Up: Mathematical Functions (math.h) [Contents][Index]
ldexp, ldexpf—load exponentSynopsis
#include <math.h>double ldexp(double val, int exp);float ldexpf(float val, int exp);
Descriptionldexp calculates the value val times 2 to the power exp.ldexpf is identical, save that it takes and returns floatrather than double values.
Returnsldexp returns the calculated value.
Underflow and overflow both set errno to ERANGE.On underflow, ldexp and ldexpf return 0.0.On overflow, ldexp returns plus or minus HUGE_VAL.
Portabilityldexp is ANSI. ldexpf is an extension.
Next: log10, log10f—base 10 logarithms, Previous: ldexp, ldexpf—load exponent, Up: Mathematical Functions (math.h) [Contents][Index]
log, logf—natural logarithmsSynopsis
#include <math.h>double log(double x);float logf(float x);
Description
Return the natural logarithm of x, that is, its logarithm base e(where e is the base of the natural system of logarithms, 2.71828…).log and logf are identical save for the return and argument types.
Returns
Normally, returns the calculated value. When x is zero, thereturned value is -HUGE_VAL and errno is set to ERANGE.When x is negative, the returned value is NaN (not a number) anderrno is set to EDOM.
Portabilitylog is ANSI. logf is an extension.
Next: log1p, log1pf—log of 1 + x, Previous: log, logf—natural logarithms, Up: Mathematical Functions (math.h) [Contents][Index]
log10, log10f—base 10 logarithmsSynopsis
#include <math.h>double log10(double x);float log10f(float x);
Descriptionlog10 returns the base 10 logarithm of x.It is implemented as log(x) / log(10).
log10f is identical, save that it takes and returns float values.
Returnslog10 and log10f return the calculated value.
See the description of log for information on errors.
Portabilitylog10 is ANSI C. log10f is an extension.
Next: log2, log2f—base 2 logarithm, Previous: log10, log10f—base 10 logarithms, Up: Mathematical Functions (math.h) [Contents][Index]
log1p, log1pf—log of 1 + xSynopsis
#include <math.h>double log1p(double x);float log1pf(float x);
Descriptionlog1p calculatesthe natural logarithm of 1+x. You can use log1p ratherthan ‘log(1+x)’ for greater precision when x is verysmall.
log1pf calculates the same thing, but accepts and returnsfloat values rather than double.
Returnslog1p returns a double, the natural log of 1+x.log1pf returns a float, the natural log of 1+x.
Portability
Neither log1p nor log1pf is required by ANSI C or by the System VInterface Definition (Issue 2).
Next: logb, logbf—get exponent of floating-point number, Previous: log1p, log1pf—log of 1 + x, Up: Mathematical Functions (math.h) [Contents][Index]
log2, log2f—base 2 logarithmSynopsis
#include <math.h>double log2(double x);float log2f(float x);
Description
The log2 functions compute the base-2 logarithm of x. A domain erroroccurs if the argument is less than zero. A range error occurs if theargument is zero.
The Newlib implementations are not full, intrinisic calculations, butrather are derivatives based on log. (Accuracy might be slightly off froma direct calculation.) In addition to functions, they are also implemented asmacros defined in math.h:
#define log2(x) (log (x) / _M_LN2) #define log2f(x) (logf (x) / (float) _M_LN2)
To use the functions instead, just undefine the macros first.
Returns
The log2 functions returnlog base-2(x)on success.When x is zero, thereturned value is -HUGE_VAL and errno is set to ERANGE.When x is negative, the returned value is NaN (not a number) anderrno is set to EDOM.
Portability
C99, POSIX, System V Interface Definition (Issue 6).
Next: lrint, lrintf, llrint, llrintf—round to integer, Previous: log2, log2f—base 2 logarithm, Up: Mathematical Functions (math.h) [Contents][Index]
logb, logbf—get exponent of floating-point numberSynopsis
#include <math.h>double logb(double x);float logbf(float x);
Description
The logb functions extract the exponent of x, as a signed integer valuein floating-point format. If x is subnormal it is treated as though it werenormalized; thus, for positive finite x,1 <= (x * FLT_RADIX to the power (-logb(x))) < FLT_RADIX.A domain error may occur if the argument is zero.In this floating-point implementation, FLT_RADIX is 2. Which also meansthat for finite x, logb(x) = floor(log2(fabs(x))).
All nonzero, normal numbers can be described asm * 2**p, where 1.0 <= m < 2.0.The logb functions examine the argument x, and return p.The frexp functions are similar to the logb functions, butreturning m adjusted to the interval [.5, 1) or 0, and p+1.
Returns
When x is:
+inf or -inf, +inf is returned;
NaN, NaN is returned;
0, -inf is returned, and the divide-by-zero exception is raised;
otherwise, the logb functions return the signed exponent of x.
Portability
ANSI C, POSIX
See Also
frexp, ilogb
Next: lround, lroundf, llround, llroundf—round to integer, to nearest, Previous: logb, logbf—get exponent of floating-point number, Up: Mathematical Functions (math.h) [Contents][Index]
lrint, lrintf, llrint, llrintf—round to integerSynopsis
#include <math.h>long int lrint(double x);long int lrintf(float x);long long int llrint(double x);long long int llrintf(float x);
Description
The lrint and llrint functions round their argument to the nearestinteger value, using the current rounding direction. If the rounded value isoutside the range of the return type, the numeric result is unspecified. Arange error may occur if the magnitude of x is too large.The "inexact" floating-point exception is raised in implementations thatsupport it when the result differs in value from the argument (i.e., whena fraction actually has been truncated).
Returns
x rounded to an integral value, using the current rounding direction.
See Alsolround
Portability
ANSI C, POSIX
Next: modf, modff—split fractional and integer parts, Previous: lrint, lrintf, llrint, llrintf—round to integer, Up: Mathematical Functions (math.h) [Contents][Index]
lround, lroundf, llround, llroundf—round to integer, to nearestSynopsis
#include <math.h>long int lround(double x);long int lroundf(float x);long long int llround(double x);long long int llroundf(float x);
Description
The lround and llround functions round their argument to thenearest integer value, rounding halfway cases away from zero, regardlessof the current rounding direction. If the rounded value is outside therange of the return type, the numeric result is unspecified (dependingupon the floating-point implementation, not the library). A rangeerror may occur if the magnitude of x is too large.
Returns
x rounded to an integral value as an integer.
See Also
See the round functions for the return being the same floating-point typeas the argument. lrint, llrint.
Portability
ANSI C, POSIX
Next: nan, nanf—representation of “Not a Number”, Previous: lround, lroundf, llround, llroundf—round to integer, to nearest, Up: Mathematical Functions (math.h) [Contents][Index]
modf, modff—split fractional and integer partsSynopsis
#include <math.h>double modf(double val, double *ipart);float modff(float val, float *ipart);
Descriptionmodf splits the double val apart into an integer partand a fractional part, returning the fractional part andstoring the integer part in *ipart. No roundingwhatsoever is done; the sum of the integer and fractionalparts is guaranteed to be exactly equal to val. Thatis, if realpart = modf(val, &intpart); then‘realpart+intpart’ is the same as val.modff is identical, save that it takes and returnsfloat rather than double values.
Returns
The fractional part is returned. Each result has the samesign as the supplied argument val.
Portabilitymodf is ANSI C. modff is an extension.
Next: nearbyint, nearbyintf—round to integer, Previous: modf, modff—split fractional and integer parts, Up: Mathematical Functions (math.h) [Contents][Index]
nan, nanf—representation of “Not a Number”Synopsis
#include <math.h>double nan(const char *unused);float nanf(const char *unused);
Descriptionnan and nanf return an IEEE NaN (Not a Number) indouble- and single-precision arithmetic respectively. Theargument is currently disregarded.
Next: nextafter, nextafterf—get next number, Previous: nan, nanf—representation of “Not a Number”, Up: Mathematical Functions (math.h) [Contents][Index]
nearbyint, nearbyintf—round to integerSynopsis
#include <math.h>double nearbyint(double x);float nearbyintf(float x);
Description
The nearbyint functions round their argument to an integer value infloating-point format, using the current rounding direction and(supposedly) without raising the "inexact" floating-point exception.See the rint functions for the same function with the "inexact"floating-point exception being raised when appropriate.
Bugs
Newlib does not support the floating-point exception model, so thatthe floating-point exception control is not present and thereby what maybe seen will be compiler and hardware dependent in this regard.The Newlib nearbyint functions are identical to the rintfunctions with respect to the floating-point exception behavior, andwill cause the "inexact" exception to be raised for most targets.
Returns
x rounded to an integral value, using the current rounding direction.
Portability
ANSI C, POSIX
See Alsorint, round
Next: pow, powf—x to the power y, Previous: nearbyint, nearbyintf—round to integer, Up: Mathematical Functions (math.h) [Contents][Index]
nextafter, nextafterf—get next numberSynopsis
#include <math.h>double nextafter(double val, double dir);float nextafterf(float val, float dir);
Descriptionnextafter returns the double-precision floating-point numberclosest to val in the direction toward dir. nextafterfperforms the same operation in single precision. For example,nextafter(0.0,1.0) returns the smallest positive number which isrepresentable in double precision.
Returns
Returns the next closest number to val in the direction towarddir.
Portability
Neither nextafter nor nextafterf is required by ANSI Cor by the System V Interface Definition (Issue 2).
Next: pow10, pow10f—base 10 power functions, Previous: nextafter, nextafterf—get next number, Up: Mathematical Functions (math.h) [Contents][Index]
pow, powf—x to the power ySynopsis
#include <math.h>double pow(double x, double y);float powf(float x, float y);
Descriptionpow and powf calculate x raised to the exponent y.
Returns
On success, pow and powf return the value calculated.
When the argument values would produce overflow, powreturns HUGE_VAL and set errno to ERANGE. If theargument x passed to pow or powf is a negativenoninteger, and y is also not an integer, then errnois set to EDOM. If x and y are both 0, thenpow and powf return 1.
Portabilitypow is ANSI C. powf is an extension.
Next: remainder, remainderf—round and remainder, Previous: pow, powf—x to the power y, Up: Mathematical Functions (math.h) [Contents][Index]
pow10, pow10f—base 10 power functionsSynopsis
#include <math.h>double pow10(double x);float pow10f(float x);
Descriptionpow10 and pow10f calculate 10 ^ x, that is,10 raised to the power x.
Returns
On success, pow10 and pow10f return the calculated value.If the result underflows, the returned value is 0. If theresult overflows, the returned value is HUGE_VAL. Ineither case, errno is set to ERANGE.
Portabilitypow10 and pow10f are GNU extensions.
Next: remquo, remquof—remainder and part of quotient, Previous: pow10, pow10f—base 10 power functions, Up: Mathematical Functions (math.h) [Contents][Index]
remainder, remainderf—round and remainderSynopsis
#include <math.h>double remainder(double x, double y);float remainderf(float x, float y);
Descriptionremainder and remainderf find the remainder ofx/y; this value is in the range -y/2 .. +y/2.
Returnsremainder returns the integer result as a double.
Portabilityremainder is a System V release 4.remainderf is an extension.
Next: rint, rintf—round to integer, Previous: remainder, remainderf—round and remainder, Up: Mathematical Functions (math.h) [Contents][Index]
remquo, remquof—remainder and part of quotientSynopsis
#include <math.h>double remquo(double x, double y, int *quo);float remquof(float x, float y, int *quo);
Description
The remquo functions compute the same remainder as the remainderfunctions; this value is in the range -y/2 ... +y/2. In the objectpointed to by quo they store a value whose sign is the sign of x/yand whose magnitude is congruent modulo 2**n to the magnitude of the integralquotient of x/y. (That is, quo is given the n lsbs of thequotient, not counting the sign.) This implementation uses n=31 if int is 32bits or more, otherwise, n is 1 less than the width of int.
For example:
remquo(-29.0, 3.0, &quo)
returns -1.0 and sets quo=10, and
remquo(-98307.0, 3.0, &quo)
returns -0.0 and sets quo=-32769, although for 16-bit int, quo=-1. Inthe latter case, the actual quotient of -(32769=0x8001) is reduced to -1because of the 15-bit limitation for the quotient.
Returns
When either argument is NaN, NaN is returned. If y is 0 or x isinfinite (and neither is NaN), a domain error occurs (i.e. the "invalid"floating point exception is raised or errno is set to EDOM), and NaN isreturned.Otherwise, the remquo functions return x REM y.
Bugs
IEEE754-2008 calls for remquo(subnormal, inf) to cause the "underflow"floating-point exception. This implementation does not.
Portability
C99, POSIX.
Next: round, roundf—round to integer, to nearest, Previous: remquo, remquof—remainder and part of quotient, Up: Mathematical Functions (math.h) [Contents][Index]
rint, rintf—round to integerSynopsis
#include <math.h>double rint(double x);float rintf(float x);
Description
The rint functions round their argument to an integer value infloating-point format, using the current rounding direction. Theyraise the "inexact" floating-point exception if the result differsin value from the argument. See the nearbyint functions for thesame function with the "inexact" floating-point exception never beingraised. Newlib does not directly support floating-point exceptions.The rint functions are written so that the "inexact" exception israised in hardware implementations that support it, even though Newlibdoes not provide access.
Returns
x rounded to an integral value, using the current rounding direction.
Portability
ANSI C, POSIX
See Alsonearbyint, round
Next: scalbn, scalbnf, scalbln, scalblnf—scale by power of FLT_RADIX (=2), Previous: rint, rintf—round to integer, Up: Mathematical Functions (math.h) [Contents][Index]
round, roundf—round to integer, to nearestSynopsis
#include <math.h>double round(double x);float roundf(float x);
Description
The round functions round their argument to the nearest integervalue in floating-point format, rounding halfway cases away from zero,regardless of the current rounding direction. (While the "inexact"floating-point exception behavior is unspecified by the C standard, theround functions are written so that "inexact" is not raised if theresult does not equal the argument, which behavior is as recommended byIEEE 754 for its related functions.)
Returns
x rounded to an integral value.
Portability
ANSI C, POSIX
See Alsonearbyint, rint
Next: signbit—Does floating-point number have negative sign?, Previous: round, roundf—round to integer, to nearest, Up: Mathematical Functions (math.h) [Contents][Index]
scalbn, scalbnf, scalbln, scalblnf—scale by power of FLT_RADIX (=2)Synopsis
#include <math.h>double scalbn(double x, int n);float scalbnf(float x, int n);double scalbln(double x, long int n);float scalblnf(float x, long int n);
Description
The scalbn and scalbln functions compute x times FLT_RADIX to the power n.efficiently. The result is computed by manipulating the exponent, rather thanby actually performing an exponentiation or multiplication. In thisfloating-point implementation FLT_RADIX=2, which makes the scalbnfunctions equivalent to the ldexp functions.
Returns
x times 2 to the power n. A range error may occur.
Portability
ANSI C, POSIX
See Alsoldexp
Next: sin, sinf, cos, cosf—sine or cosine, Previous: scalbn, scalbnf, scalbln, scalblnf—scale by power of FLT_RADIX (=2), Up: Mathematical Functions (math.h) [Contents][Index]
signbit—Does floating-point number have negative sign?Synopsis
#include <math.h>int signbit(real-floating x);
Description
The signbit macro determines whether the sign of its argument value isnegative. The macro reports the sign of all values, including infinities,zeros, and NaNs. If zero is unsigned, it is treated as positive. As shown inthe synopsis, the argument is "real-floating," meaning that any of the realfloating-point types (float, double, etc.) may be given to it.
Note that because of the possibilities of signed 0 and NaNs, the expression"x < 0.0" does not give the same result as signbit in all cases.
Returns
The signbit macro returns a nonzero value if and only if the sign of itsargument value is negative.
Portability
C99, POSIX.
Next: sinh, sinhf—hyperbolic sine, Previous: signbit—Does floating-point number have negative sign?, Up: Mathematical Functions (math.h) [Contents][Index]
sin, sinf, cos, cosf—sine or cosineSynopsis
#include <math.h>double sin(double x);float sinf(float x);double cos(double x);float cosf(float x);
Descriptionsin and cos compute (respectively) the sine and cosineof the argument x. Angles are specified in radians.
sinf and cosf are identical, save that they take andreturn float values.
Returns
The sine or cosine of x is returned.
Portabilitysin and cos are ANSI C. sinf and cosf are extensions.
Next: sqrt, sqrtf—positive square root, Previous: sin, sinf, cos, cosf—sine or cosine, Up: Mathematical Functions (math.h) [Contents][Index]
sinh, sinhf—hyperbolic sineSynopsis
#include <math.h>double sinh(double x);float sinhf(float x);
Descriptionsinh computes the hyperbolic sine of the argument x.Angles are specified in radians. sinh(x) is defined as
(exp(x) - exp(-x))/2
sinhf is identical, save that it takes and returns float values.
Returns
The hyperbolic sine of x is returned.
When the correct result is too large to be representable (anoverflow), sinh returns HUGE_VAL with theappropriate sign, and sets the global value errno toERANGE.
Portabilitysinh is ANSI C. sinhf is an extension.
Next: tan, tanf—tangent, Previous: sinh, sinhf—hyperbolic sine, Up: Mathematical Functions (math.h) [Contents][Index]
sqrt, sqrtf—positive square rootSynopsis
#include <math.h>double sqrt(double x);float sqrtf(float x);
Descriptionsqrt computes the positive square root of the argument.
Returns
On success, the square root is returned. If x is real andpositive, then the result is positive. If x is real andnegative, the global value errno is set to EDOM (domain error).
Portabilitysqrt is ANSI C. sqrtf is an extension.
Next: tanh, tanhf—hyperbolic tangent, Previous: sqrt, sqrtf—positive square root, Up: Mathematical Functions (math.h) [Contents][Index]
tan, tanf—tangentSynopsis
#include <math.h>double tan(double x);float tanf(float x);
Descriptiontan computes the tangent of the argument x.Angles are specified in radians.
tanf is identical, save that it takes and returns float values.
Returns
The tangent of x is returned.
Portabilitytan is ANSI. tanf is an extension.
Next: trunc, truncf—round to integer, towards zero, Previous: tan, tanf—tangent, Up: Mathematical Functions (math.h) [Contents][Index]
tanh, tanhf—hyperbolic tangentSynopsis
#include <math.h>double tanh(double x);float tanhf(float x);
Description
tanh computes the hyperbolic tangent ofthe argument x. Angles are specified in radians.
tanh(x) is defined as
sinh(x)/cosh(x)
tanhf is identical, save that it takes and returns float values.
Returns
The hyperbolic tangent of x is returned.
Portabilitytanh is ANSI C. tanhf is an extension.
Previous: tanh, tanhf—hyperbolic tangent, Up: Mathematical Functions (math.h) [Contents][Index]
trunc, truncf—round to integer, towards zeroSynopsis
#include <math.h>double trunc(double x);float truncf(float x);
Description
The trunc functions round their argument to the integer value, infloating format, nearest to but no larger in magnitude than theargument, regardless of the current rounding direction. (While the"inexact" floating-point exception behavior is unspecified by the Cstandard, the trunc functions are written so that "inexact" is notraised if the result does not equal the argument, which behavior is asrecommended by IEEE 754 for its related functions.)
Returns
x truncated to an integral value.
Portability
ANSI C, POSIX
Next: Floating-Point Environment (fenv.h), Previous: Mathematical Functions (math.h), Up: LIBM [Contents][Index]
This chapter groups the complex mathematical functions. Thecorresponding definitions and declarations are in complex.h.Functions and documentations are taken from NetBSD.
cabs, cabsf, cabsl—complex absolute-valuecacos, cacosf—complex arc cosinecacosh, cacoshf—complex arc hyperbolic cosinecarg, cargf—argument (phase angle)casin, casinf—complex arc sinecasinh, casinhf—complex arc hyperbolic sinecatan, catanf—complex arc tangentcatanh, catanhf—complex arc hyperbolic tangentccos, ccosf—complex cosineccosh, ccoshf—complex hyperbolic cosinecexp, cexpf—complex base-e exponentialcimag, cimagf, cimagl—imaginary partclog, clogf—complex base-e logarithmclog10, clog10f—complex base-10 logarithmconj, conjf—complex conjugatecpow, cpowf—complex powercproj, cprojf— Riemann sphere projectioncreal, crealf, creall—real partcsin, csinf—complex sinecsinh, csinhf—complex hyperbolic sinecsqrt, csqrtf—complex square rootctan, ctanf—complex tangentctanh, ctanf—complex hyperbolic tangentNext: cacos, cacosf—complex arc cosine, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
cabs, cabsf, cabsl—complex absolute-valueSynopsis
#include <complex.h>double cabs(double complex z);float cabsf(float complex z);long double cabsl(long double complex z);
Description
These functions compute compute the complex absolute value(also called norm, modulus, or magnitude) of z.
cabsf is identical to cabs, except that it performsits calculations on float complex.
cabsl is identical to cabs, except that it performsits calculations on long double complex.
Returns
The cabs* functions return the complex absolute value.
Portabilitycabs, cabsf and cabsl are ISO C99
Next: cacosh, cacoshf—complex arc hyperbolic cosine, Previous: cabs, cabsf, cabsl—complex absolute-value, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
cacos, cacosf—complex arc cosineSynopsis
#include <complex.h>double complex cacos(double complex z);float complex cacosf(float complex z);
Description
These functions compute the complex arc cosine of z,with branch cuts outside the interval [-1, +1] along the real axis.
cacosf is identical to cacos, except that it performsits calculations on floats complex.
Returns
These functions return the complex arc cosine value, in the rangeof a strip mathematically unbounded along the imaginary axisand in the interval [0, pi] along the real axis.
Portabilitycacos and cacosf are ISO C99
Next: carg, cargf—argument (phase angle), Previous: cacos, cacosf—complex arc cosine, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
cacosh, cacoshf—complex arc hyperbolic cosineSynopsis
#include <complex.h>double complex cacosh(double complex z);float complex cacoshf(float complex z);
Description
These functions compute the complex arc hyperbolic cosine of z,with a branch cut at values less than 1 along the real axis.
cacoshf is identical to cacosh, except that it performsits calculations on floats complex.
Returns
These functions return the complex arc hyperbolic cosine value,in the range of a half-strip of non-negative values along thereal axis and in the interval [-i * pi, +i * pi] along theimaginary axis.
Portabilitycacosh and cacoshf are ISO C99
Next: casin, casinf—complex arc sine, Previous: cacosh, cacoshf—complex arc hyperbolic cosine, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
carg, cargf—argument (phase angle)Synopsis
#include <complex.h>double carg(double complex z);float cargf(float complex z);
Description
These functions compute the argument (also called phase angle)of z, with a branch cut along the negative real axis.
cargf is identical to carg, except that it performsits calculations on floats complex.
Returns
The carg functions return the value of the argument in theinterval [-pi, +pi]
Portabilitycarg and cargf are ISO C99
Next: casinh, casinhf—complex arc hyperbolic sine, Previous: carg, cargf—argument (phase angle), Up: Mathematical Complex Functions (complex.h) [Contents][Index]
casin, casinf—complex arc sineSynopsis
#include <complex.h>double complex casin(double complex z);float complex casinf(float complex z);
Description
These functions compute the complex arc sine of z,with branch cuts outside the interval [-1, +1] along the real axis.
casinf is identical to casin, except that it performsits calculations on floats complex.
Returns
These functions return the complex arc sine value, in the rangeof a strip mathematically unbounded along the imaginary axisand in the interval [-pi/2, +pi/2] along the real axis.
Portabilitycasin and casinf are ISO C99
Next: catan, catanf—complex arc tangent, Previous: casin, casinf—complex arc sine, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
casinh, casinhf—complex arc hyperbolic sineSynopsis
#include <complex.h>double complex casinh(double complex z);float complex casinhf(float complex z);
Description
These functions compute the complex arc hyperbolic sine of z,with branch cuts outside the interval [-i, +i] along theimaginary axis.
casinhf is identical to casinh, except that it performsits calculations on floats complex.
Returns
These functions return the complex arc hyperbolic sine value,in the range of a strip mathematically unbounded along thereal axis and in the interval [-i*p/2, +i*p/2] along theimaginary axis.
Portabilitycasinh and casinhf are ISO C99
Next: catanh, catanhf—complex arc hyperbolic tangent, Previous: casinh, casinhf—complex arc hyperbolic sine, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
catan, catanf—complex arc tangentSynopsis
#include <complex.h>double complex catan(double complex z);float complex catanf(float complex z);
Description
These functions compute the complex arc tangent of z,with branch cuts outside the interval [-i, +i] along theimaginary axis.
catanf is identical to catan, except that it performsits calculations on floats complex.
Returns
These functions return the complex arc tangent value, in the rangeof a strip mathematically unbounded along the imaginary axisand in the interval [-pi/2, +pi/2] along the real axis.
Portabilitycatan and catanf are ISO C99
Next: ccos, ccosf—complex cosine, Previous: catan, catanf—complex arc tangent, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
catanh, catanhf—complex arc hyperbolic tangentSynopsis
#include <complex.h>double complex catanh(double complex z);float complex catanhf(float complex z);
Description
These functions compute the complex arc hyperbolic tan of z,with branch cuts outside the interval [-1, +1] along thereal axis.
catanhf is identical to catanh, except that it performsits calculations on floats complex.
Returns
These functions return the complex arc hyperbolic tangent value,in the range of a strip mathematically unbounded along thereal axis and in the interval [-i*p/2, +i*p/2] along theimaginary axis.
Portabilitycatanh and catanhf are ISO C99
Next: ccosh, ccoshf—complex hyperbolic cosine, Previous: catanh, catanhf—complex arc hyperbolic tangent, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
ccos, ccosf—complex cosineSynopsis
#include <complex.h>double complex ccos(double complex z);float complex ccosf(float complex z);
Description
These functions compute the complex cosine of z.
ccosf is identical to ccos, except that it performsits calculations on floats complex.
Returns
These functions return the complex cosine value.
Portabilityccos and ccosf are ISO C99
Next: cexp, cexpf—complex base-e exponential, Previous: ccos, ccosf—complex cosine, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
ccosh, ccoshf—complex hyperbolic cosineSynopsis
#include <complex.h>double complex ccosh(double complex z);float complex ccoshf(float complex z);
Description
These functions compute the complex hyperbolic cosine of z.
ccoshf is identical to ccosh, except that it performsits calculations on floats complex.
Returns
These functions return the complex hyperbolic cosine value.
Portabilityccosh and ccoshf are ISO C99
Next: cimag, cimagf, cimagl—imaginary part, Previous: ccosh, ccoshf—complex hyperbolic cosine, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
cexp, cexpf—complex base-e exponentialSynopsis
#include <complex.h>double complex cexp(double complex z);float complex cexpf(float complex z);
Description
These functions compute the complex base-e exponential of z.
cexpf is identical to cexp, except that it performsits calculations on floats complex.
Returns
The cexp functions return the complex base-e exponential value.
Portabilitycexp and cexpf are ISO C99
Next: clog, clogf—complex base-e logarithm, Previous: cexp, cexpf—complex base-e exponential, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
cimag, cimagf, cimagl—imaginary partSynopsis
#include <complex.h>double cimag(double complex z);float cimagf(float complex z);long double cimagl(long double complex z);
Description
These functions compute the imaginary part of z.
cimagf is identical to cimag, except that it performsits calculations on float complex.
cimagl is identical to cimag, except that it performsits calculations on long double complex.
Returns
The cimag* functions return the imaginary part value (as a real).
Portabilitycimag, cimagf and cimagl are ISO C99
Next: clog10, clog10f—complex base-10 logarithm, Previous: cimag, cimagf, cimagl—imaginary part, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
clog, clogf—complex base-e logarithmSynopsis
#include <complex.h>double complex clog(double complex z);float complex clogf(float complex z);
Description
These functions compute the complex natural (base-e) logarithmof z, with a branch cut along the negative real axis.
clogf is identical to clog, except that it performsits calculations on floats complex.
Returns
The clog functions return the complex natural logarithm value, inthe range of a strip mathematically unbounded along the real axisand in the interval [-i*pi , +i*pi] along the imaginary axis.
Portabilityclog and clogf are ISO C99
Next: conj, conjf—complex conjugate, Previous: clog, clogf—complex base-e logarithm, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
clog10, clog10f—complex base-10 logarithmSynopsis
#define _GNU_SOURCE#include <complex.h>double complex clog10(double complex z);float complex clog10f(float complex z);
Description
These functions compute the complex base-10 logarithm of z.clog10 is equivalent to clog(z)/log(10).
clog10f is identical to clog10, except that it performsits calculations on floats complex.
Returns
The clog10 functions return the complex base-10 logarithm value.
Portabilityclog10 and clog10f are GNU extensions.
Next: cpow, cpowf—complex power, Previous: clog10, clog10f—complex base-10 logarithm, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
conj, conjf—complex conjugateSynopsis
#include <complex.h>double complex conj(double complex z);float complex conjf(float complex z);
Description
These functions compute the complex conjugate of z,by reversing the sign of its imaginary part.
conjf is identical to conj, except that it performsits calculations on floats complex.
Returns
The conj functions return the complex conjugate value.
Portabilityconj and conjf are ISO C99
Next: cproj, cprojf— Riemann sphere projection, Previous: conj, conjf—complex conjugate, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
cpow, cpowf—complex powerSynopsis
#include <complex.h>double complex cpow(double complex x, double complex y);float complex cpowf(float complex x, float complex y);
Description
The cpow functions compute the complex power function x^ypower, with a branch cut for the first parameter along thenegative real axis.
cpowf is identical to cpow, except that it performsits calculations on floats complex.
Returns
The cpow functions return the complex power function value.
Portabilitycpow and cpowf are ISO C99
Next: creal, crealf, creall—real part, Previous: cpow, cpowf—complex power, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
cproj, cprojf— Riemann sphere projectionSynopsis
#include <complex.h>double complex cproj(double complex z);float complex cprojf(float complex z);
Description
These functions compute a projection of z onto the Riemannsphere: z projects to z except that all complex infinities(even those with one infinite part and one NaN part) projectto positive infinity on the real axis. If z has an infinite part,then cproj(z) is equivalent to
INFINITY + I * copysign(0.0, cimag(z))
cprojf is identical to cproj, except that it performsits calculations on floats complex.
Returns
The cproj functions return the value of the projection ontothe Riemann sphere.
Portabilitycproj and cprojf are ISO C99
Next: csin, csinf—complex sine, Previous: cproj, cprojf— Riemann sphere projection, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
creal, crealf, creall—real partSynopsis
#include <complex.h>double creal(double complex z);float crealf(float complex z);double long creall(long double complex z);
Description
These functions compute the real part of z.
crealf is identical to creal, except that it performsits calculations on float complex.
creall is identical to creal, except that it performsits calculations on long double complex.
Returns
The creal* functions return the real part value.
Portabilitycreal, crealf and creall are ISO C99
Next: csinh, csinhf—complex hyperbolic sine, Previous: creal, crealf, creall—real part, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
csin, csinf—complex sineSynopsis
#include <complex.h>double complex csin(double complex z);float complex csinf(float complex z);
Description
These functions compute the complex sine of z.
csinf is identical to csin, except that it performsits calculations on floats complex.
Returns
These functions return the complex sine value.
Portabilitycsin and csinf are ISO C99
Next: csqrt, csqrtf—complex square root, Previous: csin, csinf—complex sine, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
csinh, csinhf—complex hyperbolic sineSynopsis
#include <complex.h>double complex csinh(double complex z);float complex csinhf(float complex z);
Description
These functions compute the complex hyperbolic sine of z.
ccoshf is identical to ccosh, except that it performsits calculations on floats complex.
Returns
These functions return the complex hyperbolic sine value.
Portabilitycsinh and csinhf are ISO C99
Next: ctan, ctanf—complex tangent, Previous: csinh, csinhf—complex hyperbolic sine, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
csqrt, csqrtf—complex square rootSynopsis
#include <complex.h>double complex csqrt(double complex z);float complex csqrtf(float complex z);
Description
These functions compute the complex square root of z, witha branch cut along the negative real axis.
csqrtf is identical to csqrt, except that it performsits calculations on floats complex.
Returns
The csqrt functions return the complex square root value, inthe range of the right halfplane (including the imaginary axis).
Portabilitycsqrt and csqrtf are ISO C99
Next: ctanh, ctanf—complex hyperbolic tangent, Previous: csqrt, csqrtf—complex square root, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
ctan, ctanf—complex tangentSynopsis
#include <complex.h>double complex ctan(double complex z);float complex ctanf(float complex z);
Description
These functions compute the complex tangent of z.
ctanf is identical to ctan, except that it performsits calculations on floats complex.
Returns
These functions return the complex tangent value.
Portabilityctan and ctanf are ISO C99
Previous: ctan, ctanf—complex tangent, Up: Mathematical Complex Functions (complex.h) [Contents][Index]
ctanh, ctanf—complex hyperbolic tangentSynopsis
#include <complex.h>double complex ctanh(double complex z);float complex ctanhf(float complex z);
Description
These functions compute the complex hyperbolic tangent of z.
ctanhf is identical to ctanh, except that it performsits calculations on floats complex.
Returns
These functions return the complex hyperbolic tangent value.
Portabilityctanh and ctanhf are ISO C99
Next: Reentrancy Properties of libm, Previous: Mathematical Complex Functions (complex.h), Up: LIBM [Contents][Index]
This chapter groups the methods used to manipulate the floating-pointstatus flags. Floating-point operations modify the floating-pointstatus flags to indicate abnormal result information.
The implementation of these methods is architecture specific.
feclearexcept—clear floating-point exceptionfegetenv—get current floating-point environmentfegetexceptflag—get floating-point status flagsfegetround—get current rounding directionfeholdexcept—save current floating-point environmentferaiseexcept—raise floating-point exceptionfesetenv—set current floating-point environmentfesetexceptflag—set floating-point status flagsfesetround—set current rounding directionfetestexcept—test floating-point exception flagsfeupdateenv—update current floating-point environmentNext: fegetenv—get current floating-point environment, Up: Floating-Point Environment (fenv.h) [Contents][Index]
feclearexcept—clear floating-point exceptionSynopsis
#include <fenv.h>int feclearexcept(int except);Link with -lm.
Description
This method attempts to clear the floating-point exceptions specifiedin except.
Returns
If the except argument is zero or all requested exceptions weresuccessfully cleared, this method returns zero. Otherwise, a non-zerovalue is returned.
Portability
ANSI C requires feclearexcept.
Not all Newlib targets have a working implementation. Refer tothe file sys/fenv.h to see the status for your target.
Next: fegetexceptflag—get floating-point status flags, Previous: feclearexcept—clear floating-point exception, Up: Floating-Point Environment (fenv.h) [Contents][Index]
fegetenv—get current floating-point environmentSynopsis
#include <fenv.h>int fegetenv(fenv_t *envp);Link with -lm.
Description
This method attempts to return the floating-point environmentin the area specified by envp.
Returns
If floating-point environment was successfully returned, thenthis method returns zero. Otherwise, a non-zero value is returned.
Portability
ANSI C requires fegetenv.
Not all Newlib targets have a working implementation. Refer tothe file sys/fenv.h to see the status for your target.
Next: fegetround—get current rounding direction, Previous: fegetenv—get current floating-point environment, Up: Floating-Point Environment (fenv.h) [Contents][Index]
fegetexceptflag—get floating-point status flagsSynopsis
#include <fenv.h>int fegetexceptflag(fexcept_t *flagp, int excepts);Link with -lm.
Description
This method attempts to store an implementation-defined representationof the states of the floating-point status flags specified by exceptsin the memory pointed to by flagp.
Returns
If the information was successfully returned, this method returnszero. Otherwise, a non-zero value is returned.
Portability
ANSI C requires fegetexceptflag.
Not all Newlib targets have a working implementation. Refer tothe file sys/fenv.h to see the status for your target.
Next: feholdexcept—save current floating-point environment, Previous: fegetexceptflag—get floating-point status flags, Up: Floating-Point Environment (fenv.h) [Contents][Index]
fegetround—get current rounding directionSynopsis
#include <fenv.h>int fegetround(void);Link with -lm.
Description
This method returns the current rounding direction.
Returns
This method returns the rounding direction, corresponding to the valueof the respective rouding macro. If the current rounding direction cannotbe determined, then a negative value is returned.
Portability
ANSI C requires fegetround.
Not all Newlib targets have a working implementation. Refer tothe file sys/fenv.h to see the status for your target.
Next: feraiseexcept—raise floating-point exception, Previous: fegetround—get current rounding direction, Up: Floating-Point Environment (fenv.h) [Contents][Index]
feholdexcept—save current floating-point environmentSynopsis
#include <fenv.h>int feholdexcept(fenv_t *envp);Link with -lm.
Description
This method attempts to save the current floating-point environmentin the fenv_t instance pointed to by envp, clear the floatingpoint status flags, and then, if supported by the target architecture,install a "non-stop" (e.g. continue on floating point exceptions) modefor all floating-point exceptions.
Returns
This method will return zero if the non-stop floating-point exceptionhandler was installed. Otherwise, a non-zero value is returned.
Portability
ANSI C requires feholdexcept.
Not all Newlib targets have a working implementation. Refer tothe file sys/fenv.h to see the status for your target.
Next: fesetenv—set current floating-point environment, Previous: feholdexcept—save current floating-point environment, Up: Floating-Point Environment (fenv.h) [Contents][Index]
feraiseexcept—raise floating-point exceptionSynopsis
#include <fenv.h>int feraiseexcept(int excepts);Link with -lm.
Description
This method attempts to raise the floating-point exceptions specifiedin excepts.
Returns
If the excepts argument is zero or all requested exceptions weresuccessfully raised, this method returns zero. Otherwise, a non-zerovalue is returned.
Portability
ANSI C requires feraiseexcept.
Not all Newlib targets have a working implementation. Refer tothe file sys/fenv.h to see the status for your target.
Next: fesetexceptflag—set floating-point status flags, Previous: feraiseexcept—raise floating-point exception, Up: Floating-Point Environment (fenv.h) [Contents][Index]
fesetenv—set current floating-point environmentSynopsis
#include <fenv.h>int fesetenv(const fenv_t *envp);Link with -lm.
Description
This method attempts to establish the floating-point environmentpointed to by envp. The argument envp must point to afloating-point environment obtained via fegetenv or feholdexceptor a floating-point environment macro such as FE_DFL_ENV.
It only sets the states of the flags as recorded in its argument, anddoes not actually raise the associated floating-point exceptions.
Returns
If floating-point environment was successfully established, thenthis method returns zero. Otherwise, a non-zero value is returned.
Portability
ANSI C requires fesetenv.
Not all Newlib targets have a working implementation. Refer tothe file sys/fenv.h to see the status for your target.
Next: fesetround—set current rounding direction, Previous: fesetenv—set current floating-point environment, Up: Floating-Point Environment (fenv.h) [Contents][Index]
fesetexceptflag—set floating-point status flagsSynopsis
#include <fenv.h>int fesetexceptflag(const fexcept_t *flagp, int excepts);Link with -lm.
Description
This method attempts to set the floating-point status flags specifiedby excepts to the states indicated by flagp. The argumentflagp must point to an fexcept_t instance obtained via callingfegetexceptflag with at least the floating-point exceptions specifiedby the argument excepts.
This method does not raise any floating-point exceptions. It onlysets the state of the flags.
Returns
If the information was successfully returned, this method returnszero. Otherwise, a non-zero value is returned.
Portability
ANSI C requires fesetexceptflag.
Not all Newlib targets have a working implementation. Refer tothe file sys/fenv.h to see the status for your target.
Next: fetestexcept—test floating-point exception flags, Previous: fesetexceptflag—set floating-point status flags, Up: Floating-Point Environment (fenv.h) [Contents][Index]
fesetround—set current rounding directionSynopsis
#include <fenv.h>int fesetround(int round);Link with -lm.
Description
This method attempts to set the current rounding direction representedby round. round must be the value of one of therounding-direction macros.
Returns
If the rounding mode was successfully established, this method returnszero. Otherwise, a non-zero value is returned.
Portability
ANSI C requires fesetround.
Not all Newlib targets have a working implementation. Refer tothe file sys/fenv.h to see the status for your target.
Next: feupdateenv—update current floating-point environment, Previous: fesetround—set current rounding direction, Up: Floating-Point Environment (fenv.h) [Contents][Index]
fetestexcept—test floating-point exception flagsSynopsis
#include <fenv.h>int fetestexcept(int except);Link with -lm.
Description
This method test the current floating-point exceptions to determinewhich of those specified in except are currently set.
Returns
This method returns the bitwise-inclusive OR of the floating pointexception macros which correspond to the currently set floating pointexceptions.
Portability
ANSI C requires fetestexcept.
Not all Newlib targets have a working implementation. Refer tothe file sys/fenv.h to see the status for your target.
Previous: fetestexcept—test floating-point exception flags, Up: Floating-Point Environment (fenv.h) [Contents][Index]
feupdateenv—update current floating-point environmentSynopsis
#include <fenv.h>int feupdateenv(const fenv_t *envp);Link with -lm.
Description
This method attempts to save the currently raised floating pointexceptions in its automatic storage, install the floating pointenvironment specified by envp, and raise the saved floatingpoint exceptions.
The argument envp must point to a floating-point environmentobtained via fegetenv or feholdexcept.
Returns
If all actions are completed successfully, then this method returns zero.Otherwise, a non-zero value is returned.
Portability
ANSI C requires feupdateenv.
Not all Newlib targets have a working implementation. Refer tothe file sys/fenv.h to see the status for your target.
Next: The long double function support of libm, Previous: Floating-Point Environment (fenv.h), Up: LIBM [Contents][Index]
libmWhen a libm function detects an exceptional case, errno may beset.
errno is a macro which expands to the per-thread error value.This makes it thread safe, and therefore reentrant.
Next: Document Index, Previous: Reentrancy Properties of libm, Up: LIBM [Contents][Index]
libmCurrently, the full set of long double math functions is only providedon platforms where long double equals double.For such platforms, the long double math functions are implemented as calls to the double versions.
Previous: The long double function support of libm, Up: LIBM [Contents][Index]
| Jump to: | M R |
|---|
| Index Entry | Section | ||
|---|---|---|---|
| | |||
| M | |||
matherr and reentrancy: | Reentrancy | ||
| | |||
| R | |||
| reentrancy: | Reentrancy | ||
| | |||
| Jump to: | M R |
|---|