# log2, log2f, log2l Functions in C

• Last Updated : 12 Apr, 2022

log2, log2f, and log2l are functions in C that compute the logarithmic of base 2 of a given number. They are part of the math.h header file.

Syntax:

#include <math.h>

double log2(double x);
float log2f(float x);
long double log2l(long double x);

Parameters:

Return Values:

Example 1: Below is the C program to implement log2(x):

## C

 `// C program to implement ` `// log2(x) ` `#include ` `#include ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``double` `result, num = 67.9; ` `    ``result = log2(num); ` `    ``printf``(``"log2(%lf) = %lf"``,  ` `            ``num, result); ` `    ``return` `0; ` `}`

Output

`log2(67.900000) = 6.085340`

Example 2: Below is the C program to implement log2f(x):

## C

 `// C program to implement  ` `// log2f(x) ` `#include ` `#include ` ` `  `// Driver code  ` `int` `main() ` `{ ` `    ``float` `result, num = 32.256; ` `    ``result = log2f(num); ` `    ``printf``(``"log2(%f) = %f"``,  ` `            ``num, result); ` `    ``return` `0; ` `}`

Output

`log2(32.256001) = 5.011496`

Example 3: Below is the C program to implement log2l(x):

## C

 `// C program to implement ` `// log2l(x) ` `#include ` `#include ` ` `  `// Driver code  ` `int` `main() ` `{ ` `    ``long` `double` `result, num = 73.1256; ` `    ``result = log2l(num); ` `    ``printf``(``"log2(%Lf) = %LF"``,  ` `            ``num, result); ` `    ``return` `0; ` `}`

Output

`log2(73.125600) = 6.192305`

My Personal Notes arrow_drop_up
Recommended Articles
Page :