PHP 8.4.0 RC2 available for testing

log

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

logNatural logarithm

Açıklama

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.

Bağımsız Değişkenler

num

The value to calculate the logarithm for

base

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

Dönen Değerler

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

Ayrıca Bakınız

  • log10() - Base-10 logarithm
  • exp() - Calculates the exponent of e
  • pow() - Exponential expression
  • error_log() - Tanımlı hata işleme yordamlarına bir hata iletisi gönderir

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