What is logbf in C?

The logbf function is defined in the <math.h> header file in C. It takes in a single parameter of type float. It then computes the logarithm of x|x| using FLT_RADIX as the base and returns the result of the floattype.

FLT_RADIX has a value of 2 in most platforms. Thus, the function performs similar to log2 for positive values.

The illustration below shows how the logbf function works:

How does logbf work?

Declaration

The logbf function is defined as follows:

float logbf(float x);

Parameters

The logbf function takes a single value of type float as a parameter.

Return value

The logbf function returns the computation of type float.

Error handling

The logbf function returns special values for certain arguments:

x Return Value
0 -INFINITY
INFINITY +INFINITY
NaN NaN

Example

The following code snippet shows how we can use the logbf function:

#include <stdio.h> // include header for printf
#include <math.h> // include header for logbf
int main ()
{
float x, result;
x = 8.0;
result = logbf(x);
printf("logbf (%f) = %f.\n", x, result);
return 0;
}

The following code snippet shows how error handling in logbf function works:

#include <stdio.h> // include header for printf
#include <math.h> // include header for logbf
int main ()
{
float x, y, result;
x = 0.0;
result = logbf(x);
printf("logbf (%f) = %f.\n", x, result);
y = INFINITY;
result = logbf(y);
printf("logbf (%f) = %f.\n", y, result);
return 0;
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved