|
|
|
Defined in header <math.h> | ||
float logf(float arg); | (1) | (since C99) |
double log(double arg); | (2) | |
longdouble logl(longdouble arg); | (3) | (since C99) |
Defined in header <tgmath.h> | ||
#define log( arg ) | (4) | (since C99) |
logl
is called. Otherwise, ifarg has integer type or the typedouble,log
is called. Otherwise,logf
is called. Ifarg is complex or imaginary, then the macro invokes the corresponding complex function (clogf,clog,clogl).Contents |
arg | - | floating-point value |
If no errors occur, the natural (base-e) logarithm ofarg (ln(arg) orloge(arg)) is returned.
If a domain error occurs, an implementation-defined value is returned (NaN where supported).
If a pole error occurs,-HUGE_VAL,-HUGE_VALF
, or-HUGE_VALL
is returned.
Errors are reported as specified inmath_errhandling
.
Domain error occurs ifarg is less than zero.
Pole error may occur ifarg is zero.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
#include <errno.h>#include <fenv.h>#include <float.h>#include <math.h>#include <stdio.h>// #pragma STDC FENV_ACCESS ON int main(void){printf("log(1) = %f\n", log(1));printf("base-5 logarithm of 125 = %f\n", log(125)/ log(5)); // special valuesprintf("log(1) = %f\n", log(1));printf("log(+Inf) = %f\n", log(INFINITY)); // error handlingerrno=0;feclearexcept(FE_ALL_EXCEPT);printf("log(0) = %f\n", log(0));if(errno==ERANGE)perror(" errno == ERANGE");if(fetestexcept(FE_DIVBYZERO))puts(" FE_DIVBYZERO raised");}
Output:
log(1) = 0.000000base-5 logarithm of 125 = 3.000000log(1) = 0.000000log(+Inf) = inflog(0) = -inf errno == ERANGE: Numerical result out of range FE_DIVBYZERO raised
(C99)(C99) | computes common (base-10) logarithm (\({\small \log_{10}{x} }\)log10(x)) (function)[edit] |
(C99)(C99)(C99) | computes base-2 logarithm (\({\small \log_{2}{x} }\)log2(x)) (function)[edit] |
(C99)(C99)(C99) | computes natural (base-e) logarithm of 1 plus the given number (\({\small \ln{(1+x)} }\)ln(1+x)) (function)[edit] |
(C99)(C99) | computese raised to the given power (\({\small e^x}\)ex) (function)[edit] |
(C99)(C99)(C99) | computes the complex natural logarithm (function)[edit] |
C++ documentation forlog |