function
<cmath> <ctgmath>

logb

     double logb  (double x);      float logbf (float x);long double logbl (long double x);
     double logb (double x);      float logb (float x);long double logb (long double x);     double logb (T x);           // additional overloads for integral types
Compute floating-point base logarithm
Returns the logarithm of |x|, using FLT_RADIX as base for the logarithm.

On most platforms, FLT_RADIX is 2, and thus this function is equivalent to log2 for positive values.

Header <tgmath.h> provides a type-generic macro version of this function.
Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).

Parameters

x
Value whose logarithm is calculated.

Return Value

The base-FLT_RADIX logarithm of x.
If x is zero it may cause a domain error or a pole error (or no error, depending on the library implementation).

If an domain error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to EDOM.
- And math_errhandling has MATH_ERREXCEPT set: FE_INVALID is raised.

If a pole error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to ERANGE.
- And math_errhandling has MATH_ERREXCEPT set: FE_DIVBYZERO is raised.

Example

1
2
3
4
5
6
7
8
9
10
11
12
/* logb example */
#include <stdio.h>      /* printf */
#include <math.h>       /* logb */

int main ()
{
  double param, result;
  param = 1024.0;
  result = logb (param);
  printf ("logb (%f) = %f.\n", param, result );
  return 0;
}

Output:

logb (1024.000000) = 10.000000


See also