#50824 [NEW]: modulus (mod) returns wrong value
| From: | jancha at trave dot lv | Date: | Fri, 22 Jan 2010 14:46:10 +0000 |
| Subject: | #50824 [NEW]: modulus (mod) returns wrong value | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-146871@lists.php.net to get a copy of this message | ||
From: jancha at trave dot lv
Operating system: Gentoo
PHP version: 5.2.12
PHP Bug Type: Math related
Bug description: modulus (mod) returns wrong value
Description:
------------
We came accorss following case:
<?php echo 72.6 * 100 % 100;
You would expect: 60
But you get: 59
We did further analysis and got following results:
[OK] 72.0:0
[FAIL] 72.1:9
[OK] 72.2:20
[OK] 72.3:30
[OK] 72.4:40
[OK] 72.5:50
[FAIL] 72.6:59
[OK] 72.7:70
[OK] 72.8:80
[OK] 72.9:90
That makes us think that bug happens, if last digit is either 1 or 6.
Also, according to manual, operands of modulus are converted to integers by
stripping decimal part away - in our case that is not reason, as 72.6 * 100
= 7260 (float). And conversion to int should result with 7260.
Reproduce code:
---------------
<?php echo 72.6 * 100 % 100;
Expected result:
----------------
60
Actual result:
--------------
59
--
Edit bug report at http://bugs.php.net/?id=50824&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50824&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50824&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50824&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=50824&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50824&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=50824&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=50824&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=50824&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=50824&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=50824&r=support
Expected behavior: http://bugs.php.net/fix.php?id=50824&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=50824&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=50824&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=50824&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50824&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50824&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=50824&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=50824&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=50824&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=50824&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=50824&r=mysqlcfg