note 29227 added to function.log

From: Date: Thu, 06 Feb 2003 18:02:43 +0000
Subject: note 29227 added to function.log
Groups: php.notes 
Request: Send a blank email to php-notes+get-43522@lists.php.net to get a copy of this message
A minor warning: in PHP < 4.3.0, in order to get the log base 10 of a number, you have to do: $log10 = log($n)/log(10); If you want a whole number (to identify the order of magnitude), and you typecast $log10 to (int), you may not get what you expect: (int)(log(1000)/log(10)) = 2 (log(1000)/log(10)) = 3 (float with no displayed decimal places) The mathematical error in this causes the typecast to round the result down, even though the error runs out to so many decimal places that it is not displayed, and the float value looks like a whole number. Instead you may need to do: round(log($n)/log(10)-0.5,0); This will give you the order of magnitude of your number. Presumably in PHP 4.3.0+, a similar result may occur. -- http://www.php.net/manual/en/function.log.php http://master.php.net/manage/user-notes.php?action=edit+29227 http://master.php.net/manage/user-notes.php?action=delete+29227 http://master.php.net/manage/user-notes.php?action=reject+29227

« previous php.notes (#43522) next »