Rate This Document
Findability
Accuracy
Completeness
Readability

log

Compute the base-e logarithm of a real number.

Interface Definition

C interface:

float logf(float x);

double log(double x);

double log_18(double x); // Provided only in high-precision function interfaces.

Fortran interface:

RES = LOGF(X);

RES = LOG(X);

Parameters

Parameter

Type

Description

Input/Output

x

  • For logf, x is of single-precision floating-point type.
  • For log, x is of double-precision floating-point type.
  • For log_18, x is of double-precision floating-point type.

Floating-point value of the input data

Input

Return Value

  • The base-e logarithm y of x is returned. y ∈ (-INF, +INF).
  • If the input x is ±0, the return value is -∞.
  • If the input x is 1, the return value is 0.
  • If the input x is a negative number, the return value is NaN.
  • If the input x is +∞, the return value is +∞.
  • If the input x is NaN, the return value is NaN.

Dependencies

C: "km.h"

Fortran: "km.f03"

Examples

C interface:

    double pi = acos(-1); 
    // typical usage 
    double x1 = pi/2, x2 = 2.0, x3 = 125, x4 = 5; 
    // special handing 
    double a = 0.0, b = INFINITY, c = -INFINITY, d = NAN, e = 1.0; 
    // print result 
    printf("base-5 logarithm of 125 = %.15f\n", log(x3)/log(x4)); 
    printf("log(1.0) = %.15f\n", log(e)); 
    printf("log(pi/2) = %.15f\n", log(x1)); 
    printf("log(2.0) = %.15f\n", log(x2)); 
    printf("log(0.0) = %.15f\n", log(a)); 
    printf("log(INFINITY) = %.15f\n", log(b)); 
    printf("log(-INFINITY) = %.15f\n", log(c)); 
    printf("log(NAN) = %.15f\n", log(d)); 
    /* 
     *  base-5 logarithm of 125 = 3.000000000000000 
     *  log(1.0) = 0.000000000000000 
     *  log(pi/2) = 0.451582705289455 
     *  log(2.0) = 0.693147180559945 
     *  log(+0.0) = -inf 
     *  log(INFINITY) = inf 
     *  log(-INFINITY) = nan 
     *  log(NAN) = nan 
     * 
     * */

Fortran interface:

    REAL(8) :: X = 2 
    PRINT*,  LOG(X) 
    ! 
    ! OUTPUT 
    !     0.693147180559945 
    !