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.
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
- ilogb
- Integer binary logarithm (function
)
- log2
- Compute binary logarithm (function
)
- pow
- Raise to power (function
)