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:
Function |
Parameter |
log2(x) |
x => double |
log2f(x) |
x => float |
log2l(x) |
x => long double |
Return Values:
Function |
Return Value |
log2(x) |
log2(x) => double |
log2f(x) |
log2(x) => float |
log2l(x) |
log2(x) => long double |
Example 1: Below is the C program to implement log2(x):
C
#include <math.h>
#include <stdio.h>
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
#include <stdio.h>
#include <math.h>
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
#include <math.h>
#include <stdio.h>
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...