log, logf, logl

Header: <math.h>

1-3) Computes the natural (base e) logarithm of arg.

# Declarations

float logf( float arg );

(since C99)

double log( double arg );
long double logl( long double arg );

(since C99)

#define log( arg )

(since C99)

# Parameters

# Return value

If no errors occur, the natural (base-e) logarithm of arg (ln(arg) or loge(arg)) is returned.

# Example

#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 values
    printf("log(1) = %f\n", log(1));
    printf("log(+Inf) = %f\n", log(INFINITY));
 
    // error handling
    errno = 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");
}

# See also