Next: Hyperbolic Functions, Previous: Inverse Trig Functions, Up: Mathematics

— Function: double **exp** (`double x`)

— Function: floatexpf(float x)

— Function: long doubleexpl(long double x)

These functions compute

`e`

(the base of natural logarithms) raised to the powerx.If the magnitude of the result is too large to be representable,

`exp`

signals overflow.

— Function: double **exp2** (`double x`)

— Function: floatexp2f(float x)

— Function: long doubleexp2l(long double x)

These functions compute

`2`

raised to the powerx. Mathematically,`exp2 (x)`

is the same as`exp (x * log (2))`

.

— Function: double **exp10** (`double x`)

— Function: floatexp10f(float x)

— Function: long doubleexp10l(long double x)

— Function: doublepow10(double x)

— Function: floatpow10f(float x)

— Function: long doublepow10l(long double x)

These functions compute

`10`

raised to the powerx. Mathematically,`exp10 (x)`

is the same as`exp (x * log (10))`

.These functions are GNU extensions. The name

`exp10`

is preferred, since it is analogous to`exp`

and`exp2`

.

— Function: double **log** (`double x`)

— Function: floatlogf(float x)

— Function: long doublelogl(long double x)

These functions compute the natural logarithm of

x.`exp (log (`

x`))`

equalsx, exactly in mathematics and approximately in C.If

xis negative,`log`

signals a domain error. Ifxis zero, it returns negative infinity; ifxis too close to zero, it may signal overflow.

— Function: double **log10** (`double x`)

— Function: floatlog10f(float x)

— Function: long doublelog10l(long double x)

These functions return the base-10 logarithm of

x.`log10 (`

x`)`

equals`log (`

x`) / log (10)`

.

— Function: double **log2** (`double x`)

— Function: floatlog2f(float x)

— Function: long doublelog2l(long double x)

These functions return the base-2 logarithm of

x.`log2 (`

x`)`

equals`log (`

x`) / log (2)`

.

— Function: double **logb** (`double x`)

— Function: floatlogbf(float x)

— Function: long doublelogbl(long double x)

These functions extract the exponent of

xand return it as a floating-point value. If`FLT_RADIX`

is two,`logb`

is equal to`floor (log2 (x))`

, except it's probably faster.If

xis de-normalized,`logb`

returns the exponentxwould have if it were normalized. Ifxis infinity (positive or negative),`logb`

returns ∞. Ifxis zero,`logb`

returns ∞. It does not signal.

— Function: int **ilogb** (`double x`)

— Function: intilogbf(float x)

— Function: intilogbl(long double x)

These functions are equivalent to the corresponding

`logb`

functions except that they return signed integer values.

Since integers cannot represent infinity and NaN, `ilogb`

instead
returns an integer that can't be the exponent of a normal floating-point
number. `math.h` defines constants so you can check for this.

— Macro: int **FP_ILOGB0**

`ilogb`

returns this value if its argument is`0`

. The numeric value is either`INT_MIN`

or`-INT_MAX`

.This macro is defined in ISO C99.

— Macro: int **FP_ILOGBNAN**

`ilogb`

returns this value if its argument is`NaN`

. The numeric value is either`INT_MIN`

or`INT_MAX`

.This macro is defined in ISO C99.

These values are system specific. They might even be the same. The
proper way to test the result of `ilogb`

is as follows:

i = ilogb (f); if (i == FP_ILOGB0 || i == FP_ILOGBNAN) { if (isnan (f)) { /* Handle NaN. */ } else if (f == 0.0) { /* Handle 0.0. */ } else { /* Some other value with large exponent, perhaps +Inf. */ } }

— Function: double **pow** (`double base, double power`)

— Function: floatpowf(float base, float power)

— Function: long doublepowl(long double base, long double power)

These are general exponentiation functions, returning

baseraised topower.Mathematically,

`pow`

would return a complex number whenbaseis negative andpoweris not an integral value.`pow`

can't do that, so instead it signals a domain error.`pow`

may also underflow or overflow the destination type.

— Function: double **sqrt** (`double x`)

— Function: floatsqrtf(float x)

— Function: long doublesqrtl(long double x)

These functions return the nonnegative square root of

x.If

xis negative,`sqrt`

signals a domain error. Mathematically, it should return a complex number.

— Function: double **cbrt** (`double x`)

— Function: floatcbrtf(float x)

— Function: long doublecbrtl(long double x)

These functions return the cube root of

x. They cannot fail; every representable real value has a representable real cube root.

— Function: double **hypot** (`double x, double y`)

— Function: floathypotf(float x, float y)

— Function: long doublehypotl(long double x, long double y)

These functions return

`sqrt (`

x`*`

x`+`

y`*`

y`)`

. This is the length of the hypotenuse of a right triangle with sides of lengthxandy, or the distance of the point (x,y) from the origin. Using this function instead of the direct formula is wise, since the error is much smaller. See also the function`cabs`

in Absolute Value.

— Function: double **expm1** (`double x`)

— Function: floatexpm1f(float x)

— Function: long doubleexpm1l(long double x)

These functions return a value equivalent to

`exp (`

x`) - 1`

. They are computed in a way that is accurate even ifxis near zero—a case where`exp (`

x`) - 1`

would be inaccurate owing to subtraction of two numbers that are nearly equal.

— Function: double **log1p** (`double x`)

— Function: floatlog1pf(float x)

— Function: long doublelog1pl(long double x)

These functions returns a value equivalent to

`log (1 +`

x`)`

. They are computed in a way that is accurate even ifxis near zero.

ISO C99 defines complex variants of some of the exponentiation and logarithm functions.

— Function: complex double **cexp** (`complex double z`)

— Function: complex floatcexpf(complex float z)

— Function: complex long doublecexpl(complex long double z)

These functions return

`e`

(the base of natural logarithms) raised to the power ofz. Mathematically, this corresponds to the valueexp (z) = exp (creal (z)) * (cos (cimag (z)) + I * sin (cimag (z)))

— Function: complex double **clog** (`complex double z`)

— Function: complex floatclogf(complex float z)

— Function: complex long doubleclogl(complex long double z)

These functions return the natural logarithm of

z. Mathematically, this corresponds to the valuelog (z) = log (cabs (z)) + I * carg (z)

`clog`

has a pole at 0, and will signal overflow ifzequals or is very close to 0. It is well-defined for all other values ofz.

— Function: complex double **clog10** (`complex double z`)

— Function: complex floatclog10f(complex float z)

— Function: complex long doubleclog10l(complex long double z)

These functions return the base 10 logarithm of the complex value

z. Mathematically, this corresponds to the valuelog (z) = log10 (cabs (z)) + I * carg (z)

These functions are GNU extensions.

— Function: complex double **csqrt** (`complex double z`)

— Function: complex floatcsqrtf(complex float z)

— Function: complex long doublecsqrtl(complex long double z)

These functions return the complex square root of the argument

z. Unlike the real-valued functions, they are defined for all values ofz.

— Function: complex double **cpow** (`complex double base, complex double power`)

— Function: complex floatcpowf(complex float base, complex float power)

— Function: complex long doublecpowl(complex long double base, complex long double power)

These functions return

baseraised to the power ofpower. This is equivalent to`cexp (y * clog (x))`