logl
Logarithm functions
Interface
#include <math.h>
double | log (double x) |
long | logl (long double x) |
float | logf (float x) |
double | log2 (double x) |
long | log2l (long double x) |
float | log2f (float x) |
double | log10 (double x) |
long | log10l (long double x) |
float | log10f (float x) |
double | log1p (double x) |
long | log1pl (long double x) |
float | log1pf (float x) |
Description
The log function computes the value of the natural logarithm of argument x. The log2 function computes the value of the logarithm of argument x to base 2. The log10 function computes the value of the logarithm of argument x to base 10. The log1p function computes the value of accurately even for very small values of x.Example:
Example - Logarithm functions
Workings
#include <math.h> #include <stdio.h> int main() { printf("\n x \t log \t log2 \t log10 \t log1p"); for(double x=0; x<=10; x+=0.5) printf("\n%lf\t%lf\t%lf\t%lf\t%lf", x, log(x), log2(x), log10(x), log1p(x)); return 0; }
Solution
Output
x log log2 log10 log1p 0.000000 -inf -inf -inf 0.000000 0.500000 -0.693147 -1.000000 -0.301030 0.405465 1.000000 0.000000 0.000000 0.000000 0.693147 1.500000 0.405465 0.584963 0.176091 0.916291 2.000000 0.693147 1.000000 0.301030 1.098612 2.500000 0.916291 1.321928 0.397940 1.252763 3.000000 1.098612 1.584963 0.477121 1.386294 3.500000 1.252763 1.807355 0.544068 1.504077 4.000000 1.386294 2.000000 0.602060 1.609438 4.500000 1.504077 2.169925 0.653213 1.704748 5.000000 1.609438 2.321928 0.698970 1.791759 5.500000 1.704748 2.459432 0.740363 1.871802 6.000000 1.791759 2.584963 0.778151 1.945910 6.500000 1.871802 2.700440 0.812913 2.014903 7.000000 1.945910 2.807355 0.845098 2.079442 7.500000 2.014903 2.906891 0.875061 2.140066 8.000000 2.079442 3.000000 0.903090 2.197225 8.500000 2.140066 3.087463 0.929419 2.251292 9.000000 2.197225 3.169925 0.954243 2.302585 9.500000 2.251292 3.247928 0.977724 2.351375 10.000000 2.302585 3.321928 1.000000 2.397895