Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is logbl in C?

Hassaan Waqar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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

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 logbl function works:

How does logbl work?

Declaration

The logbl function is defined as follows:

long double logbl(long double x);

Parameters

The logbl function takes a single value of type long double as a parameter.

Return value

The logbl function returns the computation of type long double.

Error handling

The logbl 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 logbl function:

#include <stdio.h> // include header for printf
#include <tgmath.h> // include header for logbl
int main ()
{
long double x, result;
x = 8.0;
result = logbl(x);
printf("logbl (%Lf) = %Lf.\n", x, result);
return 0;
}

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

#include <stdio.h> // include header for printf
#include <tgmath.h> // include header for logbl
int main ()
{
long double x, y, result;
x = 0.0;
result = logbl(x);
printf("logbl (%Lf) = %Lf.\n", x, result);
y = INFINITY;
result = logbl(y);
printf("logbl (%Lf) = %Lf.\n", y, result);
return 0;
}

RELATED TAGS

c

CONTRIBUTOR

Hassaan Waqar
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring