Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

# What is log2l in C?

Sheza Munir

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 log2l function is a variation of log2 function, which allows users to calculate the binary logarithm of a number, i.e., $log_2 x.$ We use this function when we need the binary logarithm of a number of datatype long double.

## Library

The log2l function is accessible from the math.h library.

## Syntax

long double log2l(long double num)


## Parameters

The function takes one parameter: a number for which a binary logarithm is needed. This parameter needs to be of long double datatype.

The number needs to be positive (greater than 0), as the logarithm of negative numbers (and 0) are undefined.

## Return value

The log2l returns the binary logarithm of the number given as a parameter. The returned number is of datatype long double.

## Code

#include <stdio.h>#include <math.h>int main(){   long double number, log2_of_number;   number = 32;   log2_of_number = log2l(number); //taking the log of number   printf("log2(%Lf) = %Lf\n", number, log2_of_number);   // log2 of number will be printed}

RELATED TAGS

c

CONTRIBUTOR

Sheza Munir 