log
(PHP 4, PHP 5)
log — Natural logarithm
Описание
float log
( float $arg
[, float $base
] )
If the optional base parameter is specified, log() returns logbase arg , otherwise log() returns the natural logarithm of arg .
Список параметров
- arg
-
The value to calculate the logarithm for
- base
-
The optinal logarithmic base to use (defaults to 'e' and so to the natural logarithm).
Возвращаемые значения
The logarithm of arg to base , if given, or the natural logarithm.
Список изменений
Версия | Описание |
---|---|
Since 4.3.0 | The optinal parameter base became available. For older versions you can calculate the logarithm in base b of a number n, but using the mathematical identity: logb(n) = log(n)/log(b), where log is the neperian (or natural) logarithm. |
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Математические расширения
- Математические функции
- abs
- acos
- acosh
- asin
- asinh
- atan2
- atan
- atanh
- base_convert
- bindec
- ceil
- cos
- cosh
- decbin
- dechex
- decoct
- deg2rad
- exp
- expm1
- floor
- fmod
- getrandmax
- hexdec
- hypot
- intdiv
- is_finite
- is_infinite
- is_nan
- lcg_value
- log10
- log1p
- log
- max
- min
- mt_getrandmax
- mt_rand
- mt_srand
- octdec
- pi
- pow
- rad2deg
- rand
- round
- sin
- sinh
- sqrt
- srand
- tan
- tanh
Коментарии
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];
}