log

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

logNatural logarithm

Опис

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.

Параметри

num

The value to calculate the logarithm for

base

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

Значення, що повертаються

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

Прогляньте також

  • 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