Featured Posts

How to Calculate Exponents in PHP

Posted by admin | Posted in PHP, Software Programs, Theory Subjects | Posted on 09-12-2009

1

To raise e to a power, use exp( ):
$exp = exp(2);// 7.3890560989307

To raise it to any power, use pow( ):
$exp = pow( 2, M_E);// 6.5808859910179

$pow = pow( 2, 10); // 1024
$pow = pow( 2, -2); // 0.25
$pow = pow( 2, 2.5);// 5.6568542494924

$pow = pow(-2, 10); // 1024
$pow = pow( 2, -2); // 0.25
$pow = pow(-2, -2.5); // NAN (Error: Not a Number)
The built-in constant M_E is an approximation of the value of e. It equals 2.7182818284590452354. So exp($n) and pow(M_E, $n) are identical.
It’s easy to create very large numbers using exp( ) and pow( ); if you outgrow PHP’s maximum size (almost 1.8e308), how to use the arbitrary precision functions. With exp( ) and pow( ), PHP returns INF (infinity) if the result is too large and NAN (not a number) on an error.

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Comments (1)

Thanks you admin :D . Nice information

VN:F [1.9.3_1094]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Post a comment

You must be logged in to post a comment.