C Standard Library

C <math.h> - logb() Function



The C <math.h> logb() function returns the logarithm of |x| (mod of argument), using FLT_RADIX as base for the logarithm.

On most platforms, FLT_RADIX is 2, which makes this function equivalent to log2() function for positive values.

Syntax

double logb  (double x);
float logbf (float x);
long double logbl (long double x);

Parameters

x Specify the value to calculate logarithm.

Return Value

Returns the base-FLT_RADIX logarithm of |x|.

Example:

In the example below, logb() function is used to calculate the base-FLT_RADIX logarithm of absolute value of given numbers.

#include <stdio.h>
#include <math.h>
 
int main (){
  printf("logb(10) = %f\n", logb(10));
  printf("logb(-10) = %f\n", logb(-10));
  return 0;
}

The output of the above code will be:

logb(10) = 3.000000
logb(-10) = 3.000000

❮ C <math.h> Library