Main Index : Reference :

log()


Description

Calculates the natural logarithm (abbreviated log) of a variable.

Definition

[float] log([float,int] x)

Parameters

x is a numeric value. Logarithms are not defined for x <= 0.

Return Value

log() returns the natural logarithm of x. The natural logarithm is the inverse to the function exp(). For more information on the use of logarithms, please refer to a math book.

Example

// Outputs "log(x) = 0.693147".

var x = 2.0;
var a = log(x);

println("log(x) = ",a);


// One can use the natural logarithm to calculate the logarithm
// in any base using the simple formula below.
//
// Outputs "logn(2,x) = 5.0000".

logn(base,x)
{
  return log(x)/log(base);
}

var x = 32.0;
var a = logn(2,x);

println("logn(2,x) = ",a);

See Also

exp(), log10()