Facebook Page Twitter Page LinkedIn Page
× C Standard Library

The C <math.h> logb() function is used to return 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.


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


x Specify the value to calculate logarithm.

Return Value

Returns the base-FLT_RADIX logarithm of |x|.


In the below example, 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