2.6 Finding the Log of a Number


You want to take the natural log of a number.

Technique

To take the natural log of a number, use PHP's log() function:

 <?php $elog = log (10); ?> 

Comments

I'm betting that right now you're thinking, "Big deal. I want to find the log of a number with a base of five, not a base of e !" Well, it looks like you forgot your calculus. Remember that

graphics/02equ01.gif


so writing this as an extensible function is

 <?php function log_n ($number, $base) {     return log ($number)/log ($base); } ?> 

Note

For logs of base ten, it is quicker to use the log10() function, like so:

 $num = log10 ($foonum); 



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net