exp
(PHP 4, PHP 5)
exp — Calculates the exponent of e
Description
float exp
( float
$arg
)
Returns e
raised to the power of arg
.
Note:
'
e
' is the base of the natural system of logarithms, or approximately 2.718282.
Parameters
-
arg
-
The argument to process
Return Values
'e' raised to the power of arg
Examples
Example #1 exp() example
<?php
echo exp(12) . "\n";
echo exp(5.7);
?>
The above example will output:
1.6275E+005 298.87
- 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
Коментарии
PHP does not have the following math function in any extensions:
frexp() - Extract Mantissa and Exponent of the Floating-Point Value
I've digged many C source codes, and found the simplest implementation as follows:
<?php
function frexp ( $float ) {
$exponent = ( floor(log($float, 2)) + 1 );
$mantissa = ( $float * pow(2, -$exponent) );
return(
array($mantissa, $exponent)
);
}
print_r(frexp(0.0345));
print_r(frexp(21.539));
?>
Array
(
[0] => 0.552
[1] => -4
)
Array
(
[0] => 0.67309375
[1] => 5
)
I have compared the results using a lot of floats against C's frexp function - they are the same.
Note that C and PHP uses different float precisions, for example "4619.3" gives:
C: 0.56387939453125, 13
PHP: 0.563879394531, 13
/Assuming default configurations./