### 19.4 Exponentiation and Logarithms ¶

Function: `double` exp `(double x)` ¶
Function: `float` expf `(float x)` ¶
Function: `long double` expl `(long double x)` ¶
Function: `_FloatN` expfN `(_FloatN x)` ¶
Function: `_FloatNx` expfNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions compute `e` (the base of natural logarithms) raised to the power x.

  If the magnitude of the result is too large to be representable, `exp` signals overflow.

Function: `double` exp2 `(double x)` ¶
Function: `float` exp2f `(float x)` ¶
Function: `long double` exp2l `(long double x)` ¶
Function: `_FloatN` exp2fN `(_FloatN x)` ¶
Function: `_FloatNx` exp2fNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions compute `2` raised to the power x. Mathematically, `exp2 (x)` is the same as `exp (x * log (2))`.

Function: `double` exp10 `(double x)` ¶
Function: `float` exp10f `(float x)` ¶
Function: `long double` exp10l `(long double x)` ¶
Function: `_FloatN` exp10fN `(_FloatN x)` ¶
Function: `_FloatNx` exp10fNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions compute `10` raised to the power x. Mathematically, `exp10 (x)` is the same as `exp (x * log (10))`.

  The `exp10` functions are from TS 18661-4:2015.

Function: `double` log `(double x)` ¶
Function: `float` logf `(float x)` ¶
Function: `long double` logl `(long double x)` ¶
Function: `_FloatN` logfN `(_FloatN x)` ¶
Function: `_FloatNx` logfNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions compute the natural logarithm of x. `exp (log (x))` equals x, exactly in mathematics and approximately in C.

  If x is negative, `log` signals a domain error. If x is zero, it returns negative infinity; if x is too close to zero, it may signal overflow.

Function: `double` log10 `(double x)` ¶
Function: `float` log10f `(float x)` ¶
Function: `long double` log10l `(long double x)` ¶
Function: `_FloatN` log10fN `(_FloatN x)` ¶
Function: `_FloatNx` log10fNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return the base-10 logarithm of x. `log10 (x)` equals `log (x) / log (10)`.

Function: `double` log2 `(double x)` ¶
Function: `float` log2f `(float x)` ¶
Function: `long double` log2l `(long double x)` ¶
Function: `_FloatN` log2fN `(_FloatN x)` ¶
Function: `_FloatNx` log2fNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return the base-2 logarithm of x. `log2 (x)` equals `log (x) / log (2)`.

Function: `double` logb `(double x)` ¶
Function: `float` logbf `(float x)` ¶
Function: `long double` logbl `(long double x)` ¶
Function: `_FloatN` logbfN `(_FloatN x)` ¶
Function: `_FloatNx` logbfNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions extract the exponent of x and return it as a floating-point value. If `FLT_RADIX` is two, `logb (x)` is similar to `floor (log2 (fabs (x)))`, except that the latter may give an incorrect integer due to intermediate rounding.

  If x is de-normalized, `logb` returns the exponent x would have if it were normalized. If x is infinity (positive or negative), `logb` returns ∞. If x is zero, `logb` returns ∞. It does not signal.

Function: `int` ilogb `(double x)` ¶
Function: `int` ilogbf `(float x)` ¶
Function: `int` ilogbl `(long double x)` ¶
Function: `int` ilogbfN `(_FloatN x)` ¶
Function: `int` ilogbfNx `(_FloatNx x)` ¶
Function: `long int` llogb `(double x)` ¶
Function: `long int` llogbf `(float x)` ¶
Function: `long int` llogbl `(long double x)` ¶
Function: `long int` llogbfN `(_FloatN x)` ¶
Function: `long int` llogbfNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions are equivalent to the corresponding `logb` functions except that they return signed integer values. The `ilogb`, `ilogbf`, and `ilogbl` functions are from ISO C99; the `llogb`, `llogbf`, `llogbl` functions are from TS 18661-1:2014; the `ilogbfN`, `ilogbfNx`, `llogbfN`, and `llogbfNx` functions are from TS 18661-3:2015.

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: `long int` FP_LLOGB0 ¶

  `llogb` returns this value if its argument is `0`. The numeric value is either `LONG_MIN` or `-LONG_MAX`.

  This macro is defined in TS 18661-1:2014.

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.

Macro: `long int` FP_LLOGBNAN ¶

  `llogb` returns this value if its argument is `NaN`. The numeric value is either `LONG_MIN` or `LONG_MAX`.

  This macro is defined in TS 18661-1:2014.

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: `float` powf `(float base, float power)` ¶
Function: `long double` powl `(long double base, long double power)` ¶
Function: `_FloatN` powfN `(_FloatN base, _FloatN power)` ¶
Function: `_FloatNx` powfNx `(_FloatNx base, _FloatNx power)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These are general exponentiation functions, returning base raised to power.

  Mathematically, `pow` would return a complex number when base is negative and power is 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` powr `(double base, double power)` ¶
Function: `float` powrf `(float base, float power)` ¶
Function: `long double` powrl `(long double base, long double power)` ¶
Function: `_FloatN` powrfN `(_FloatN base, _FloatN power)` ¶
Function: `_FloatNx` powrfNx `(_FloatNx base, _FloatNx power)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These return base raised to power, but with special cases based on `exp (power * log (base))`. For example, if base is negative, the `powr` functions always signal a domain error, but this is valid for `pow` if power is an integer.

  The `powr` functions are from TS 18661-4:2015.

Function: `double` pown `(double base, long long int power)` ¶
Function: `float` pownf `(float base, long long int power)` ¶
Function: `long double` pownl `(long double base, long long int power)` ¶
Function: `_FloatN` pownfN `(_FloatN base, long long int power)` ¶
Function: `_FloatNx` pownfNx `(_FloatNx base, long long int power)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These return base raised to power (an integer).

  The `pown` functions are from TS 18661-4:2015 (which used `intmax_t` as the type of power; the type changed to `long long int` in C23).

Function: `double` compoundn `(double x, long long int power)` ¶
Function: `float` compoundnf `(float x, long long int power)` ¶
Function: `long double` compoundnl `(long double x, long long int power)` ¶
Function: `_FloatN` compoundnfN `(_FloatN x, long long int power)` ¶
Function: `_FloatNx` compoundnfNx `(_FloatNx x, long long int power)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These return `1 + x` raised to power (an integer). If x is less than −1, `compoundn` signals a domain error.

  The `compoundn` functions are from TS 18661-4:2015 (which used `intmax_t` as the type of power; the type changed to `long long int` in C23).

Function: `double` sqrt `(double x)` ¶
Function: `float` sqrtf `(float x)` ¶
Function: `long double` sqrtl `(long double x)` ¶
Function: `_FloatN` sqrtfN `(_FloatN x)` ¶
Function: `_FloatNx` sqrtfNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return the nonnegative square root of x.

  If x is negative, `sqrt` signals a domain error. Mathematically, it should return a complex number.

Function: `double` rsqrt `(double x)` ¶
Function: `float` rsqrtf `(float x)` ¶
Function: `long double` rsqrtl `(long double x)` ¶
Function: `_FloatN` rsqrtfN `(_FloatN x)` ¶
Function: `_FloatNx` rsqrtfNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return the reciprocal of the nonnegative square root of x. If x is negative, `rsqrt` signals a domain error.

  The `rsqrt` functions are from TS 18661-4:2015.

Function: `double` cbrt `(double x)` ¶
Function: `float` cbrtf `(float x)` ¶
Function: `long double` cbrtl `(long double x)` ¶
Function: `_FloatN` cbrtfN `(_FloatN x)` ¶
Function: `_FloatNx` cbrtfNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return the cube root of x. They cannot fail; every representable real value has a real cube root, and rounding it to a representable value never causes overflow nor underflow.

Function: `double` hypot `(double x, double y)` ¶
Function: `float` hypotf `(float x, float y)` ¶
Function: `long double` hypotl `(long double x, long double y)` ¶
Function: `_FloatN` hypotfN `(_FloatN x, _FloatN y)` ¶
Function: `_FloatNx` hypotfNx `(_FloatNx x, _FloatNx y)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return `sqrt (x*x + y*y)`. This is the length of the hypotenuse of a right triangle with sides of length x and y, 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` rootn `(double x, long long int n)` ¶
Function: `float` rootnf `(float x, long long int n)` ¶
Function: `long double` rootnl `(long double x, long long int n)` ¶
Function: `_FloatN` rootnfN `(_FloatN x, long long int n)` ¶
Function: `_FloatNx` rootnfNx `(_FloatNx x, long long int n)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These return the nth root of x. If n is zero, or if x is negative and n is even, `rootn` signals a domain error.

  The `rootn` functions are from TS 18661-4:2015 (which used `intmax_t` as the type of n; the type changed to `long long int` in C23).

Function: `double` expm1 `(double x)` ¶
Function: `float` expm1f `(float x)` ¶
Function: `long double` expm1l `(long double x)` ¶
Function: `_FloatN` expm1fN `(_FloatN x)` ¶
Function: `_FloatNx` expm1fNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return a value equivalent to `exp (x) - 1`. They are computed in a way that is accurate even if x is near zero—a case where `exp (x) - 1` would be inaccurate owing to subtraction of two numbers that are nearly equal.

Function: `double` exp2m1 `(double x)` ¶
Function: `float` exp2m1f `(float x)` ¶
Function: `long double` exp2m1l `(long double x)` ¶
Function: `_FloatN` exp2m1fN `(_FloatN x)` ¶
Function: `_FloatNx` exp2m1fNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return a value equivalent to `exp2 (x) - 1`. They are computed in a way that is accurate even if x is near zero—a case where `exp2 (x) - 1` would be inaccurate owing to subtraction of two numbers that are nearly equal.

  The `exp2m1` functions are from TS 18661-4:2015.

Function: `double` exp10m1 `(double x)` ¶
Function: `float` exp10m1f `(float x)` ¶
Function: `long double` exp10m1l `(long double x)` ¶
Function: `_FloatN` exp10m1fN `(_FloatN x)` ¶
Function: `_FloatNx` exp10m1fNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return a value equivalent to `exp10 (x) - 1`. They are computed in a way that is accurate even if x is near zero—a case where `exp10 (x) - 1` would be inaccurate owing to subtraction of two numbers that are nearly equal.

  The `exp10m1` functions are from TS 18661-4:2015.

Function: `double` log1p `(double x)` ¶
Function: `float` log1pf `(float x)` ¶
Function: `long double` log1pl `(long double x)` ¶
Function: `_FloatN` log1pfN `(_FloatN x)` ¶
Function: `_FloatNx` log1pfNx `(_FloatNx x)` ¶
Function: `double` logp1 `(double x)` ¶
Function: `float` logp1f `(float x)` ¶
Function: `long double` logp1l `(long double x)` ¶
Function: `_FloatN` logp1fN `(_FloatN x)` ¶
Function: `_FloatNx` logp1fNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return a value equivalent to `log (1 + x)`. They are computed in a way that is accurate even if x is near zero.

  The `logp1` names for these functions are from TS 18661-4:2015.

Function: `double` log2p1 `(double x)` ¶
Function: `float` log2p1f `(float x)` ¶
Function: `long double` log2p1l `(long double x)` ¶
Function: `_FloatN` log2p1fN `(_FloatN x)` ¶
Function: `_FloatNx` log2p1fNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return a value equivalent to `log2 (1 + x)`. They are computed in a way that is accurate even if x is near zero.

  The `log2p1` functions are from TS 18661-4:2015.

Function: `double` log10p1 `(double x)` ¶
Function: `float` log10p1f `(float x)` ¶
Function: `long double` log10p1l `(long double x)` ¶
Function: `_FloatN` log10p1fN `(_FloatN x)` ¶
Function: `_FloatNx` log10p1fNx `(_FloatNx x)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return a value equivalent to `log10 (1 + x)`. They are computed in a way that is accurate even if x is near zero.

  The `log10p1` functions are from TS 18661-4:2015.

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

Function: `complex double` cexp `(complex double z)` ¶
Function: `complex float` cexpf `(complex float z)` ¶
Function: `complex long double` cexpl `(complex long double z)` ¶
Function: `complex _FloatN` cexpfN `(complex _FloatN z)` ¶
Function: `complex _FloatNx` cexpfNx `(complex _FloatNx z)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return `e` (the base of natural logarithms) raised to the power of z. Mathematically, this corresponds to the value

  exp (z) = exp (creal (z)) * (cos (cimag (z)) + I * sin (cimag (z)))

Function: `complex double` clog `(complex double z)` ¶
Function: `complex float` clogf `(complex float z)` ¶
Function: `complex long double` clogl `(complex long double z)` ¶
Function: `complex _FloatN` clogfN `(complex _FloatN z)` ¶
Function: `complex _FloatNx` clogfNx `(complex _FloatNx z)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return the natural logarithm of z. Mathematically, this corresponds to the value

  log (z) = log (cabs (z)) + I * carg (z)

  `clog` has a pole at 0, and will signal overflow if z equals or is very close to 0. It is well-defined for all other values of z.

Function: `complex double` clog10 `(complex double z)` ¶
Function: `complex float` clog10f `(complex float z)` ¶
Function: `complex long double` clog10l `(complex long double z)` ¶
Function: `complex _FloatN` clog10fN `(complex _FloatN z)` ¶
Function: `complex _FloatNx` clog10fNx `(complex _FloatNx z)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return the base 10 logarithm of the complex value z. Mathematically, this corresponds to the value

  log10 (z) = log10 (cabs (z)) + I * carg (z) / log (10)

  All these functions, including the `_FloatN` and `_FloatNx` variants, are GNU extensions.

Function: `complex double` csqrt `(complex double z)` ¶
Function: `complex float` csqrtf `(complex float z)` ¶
Function: `complex long double` csqrtl `(complex long double z)` ¶
Function: `complex _FloatN` csqrtfN `(_FloatN z)` ¶
Function: `complex _FloatNx` csqrtfNx `(complex _FloatNx z)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return the complex square root of the argument z. Unlike the real-valued functions, they are defined for all values of z.

Function: `complex double` cpow `(complex double base, complex double power)` ¶
Function: `complex float` cpowf `(complex float base, complex float power)` ¶
Function: `complex long double` cpowl `(complex long double base, complex long double power)` ¶
Function: `complex _FloatN` cpowfN `(complex _FloatN base, complex _FloatN power)` ¶
Function: `complex _FloatNx` cpowfNx `(complex _FloatNx base, complex _FloatNx power)` ¶

  Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

  These functions return base raised to the power of power. This is equivalent to `cexp (y * clog (x))`