PHP 8.4.0 RC4 available for testing

log

(PHP 4, PHP 5, PHP 7, PHP 8)

logNatural logarithm

Description

log(float $num, float $base = M_E): float

If the optional base parameter is specified, log() returns logbase num, otherwise log() returns the natural logarithm of num.

Parameters

num

The value to calculate the logarithm for

base

The optional logarithmic base to use (defaults to 'e' and so to the natural logarithm).

Return Values

The logarithm of num to base, if given, or the natural logarithm.

See Also

  • log10() - Base-10 logarithm
  • exp() - Calculates the exponent of e
  • pow() - Exponential expression
  • error_log() - Send an error message to the defined error handling routines

add a note

User Contributed Notes 1 note

up
-4
c0x at mail dot ru
20 years ago
more general version, works fine on negative, very big ($value > 1E+18) and very small ($value < 1E-18) numbers.

function expn($value, $prec = 3, $base = 1000, $prefix = '') {
$e = array('a', 'f', 'p', 'n', 'u', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E');
$p = min(max(floor(log(abs($value), $base)), -6), 6);
return round((float)$value / pow($base, $p), $prec) . $prefx . $e[$p + 6];
}
To Top