Bug #67738 [NEW]: log(x,10) and log10(x) are different

From: Date: Fri, 01 Aug 2014 18:27:25 +0000
Subject: Bug #67738 [NEW]: log(x,10) and log10(x) are different
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186920@lists.php.net to get a copy of this message
From: alexfbp at gmail dot com Operating system: Linux 2.6.32.3 x86_64 PHP version: 5.3.28 Package: Math related Bug Type: Bug Bug description:log(x,10) and log10(x) are different Description: ------------ Appears that internally the log(x,10) and log10(x) gets different result: For log(1000,10) maybe internally the result are 2.9999999999... maybe rounded to 3 when displayed (see the sample codes) The log10(1000) works as expected. I noticed of that when i was doing a class that i shared on phpclasses.org (http://www.phpclasses.org/package/8622) which gets the SI prefixed number of a number / numeric string. The precision are not representative, and i understand that the float format are not enough precise. It did not occur to me(perhaps by time or tiredness) better alternative to change the function by log10 when the base to be used is 10. (in the example, $log10=true) Test script: --------------- $log10=true; //Change to "false" for the second test if ($log10) { $aux1=log10(1000); } else { $aux1=log(1000,10); } $aux2=floor($aux1); $aux3=(int)$aux2; var_dump($aux1,$aux2,$aux3); Expected result: ---------------- In both cases ($log10 true and false), the var_dump() output could be like: float(3) float(3) int(3) Actual result: -------------- Works as expected for $log10=true, not for false: float(3) float(2) int(2) -- Edit bug report at https://bugs.php.net/bug.php?id=67738&edit=1 --

« previous php.bugs (#186920) next »