Bug #63476 [NEW]: Unexpected output when using log() function results

From: Date: Fri, 09 Nov 2012 20:55:58 +0000
Subject: Bug #63476 [NEW]: Unexpected output when using log() function results
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-174607@lists.php.net to get a copy of this message
From: ringtail dot jack at gmail dot com Operating system: Linux Mint 11 PHP version: 5.3.18 Package: Math related Bug Type: Bug Bug description:Unexpected output when using log() function results Description: ------------ Using the modulus operator with the results of a call to log(N, 10) produces unexpected results when N % 3 = 0. Other arithmetic operations result as expected. Equivalent operations using a call to log10(N) rather than log(N, 10) result as expected. Using echo to display log() results will display the correct value. However, passing it through printf or sprintf will print or return the correct value minus 1. [ Note: phpinfo() on my computer reports a PHP version of 5.3.5-1ubuntu7.11. I selected what seemed to be the closest version available in the web form. ] Test script: --------------- $exp = 15; $n = pow(10, $exp); $base = 10; $log = log($n, $base); echo "log: ".$log."\n"; echo "log % 3: ".$log % 3 ."\n"; echo "log via sprintf: ".sprintf('%d', $log)."\n"; $log = log10($n); echo "log10: ".$log."\n"; echo "log10 % 3: ".$log % 3 ."\n"; echo "log10 via sprintf: ".sprintf('%d', $log)."\n"; Expected result: ---------------- log: 15 log % 3: 0 log via sprintf: 15 log10: 15 log10 % 3: 0 log10 via sprintf: 15 Actual result: -------------- log: 15 log % 3: 2 log via sprintf: 14 log10: 15 log10 % 3: 0 log10 via sprintf: 15 -- Edit bug report at https://bugs.php.net/bug.php?id=63476&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63476&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63476&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63476&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63476&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=63476&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63476&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63476&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63476&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63476&r=support Expected behavior: https://bugs.php.net/fix.php?id=63476&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63476&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63476&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63476&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63476&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63476&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63476&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63476&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63476&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63476&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63476&r=mysqlcfg

« previous php.bugs (#174607) next »