Bug #61580 [Opn->Nab]: wrong calculation of Modulus operator
| From: | rasmus@php.net | Date: | Sat, 31 Mar 2012 15:49:17 +0000 |
| Subject: | Bug #61580 [Opn->Nab]: wrong calculation of Modulus operator | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169101@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61580&edit=1
ID: 61580
Updated by: rasmus@php.net
Reported by: hesam at kolahan dot com
Summary: wrong calculation of Modulus operator
-Status: Open
+Status: Not a bug
Type: Bug
Package: *Math Functions
Operating System: CentOS
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/
Thank you for your interest in PHP.
.
Previous Comments:
------------------------------------------------------------------------
[2012-03-31 12:32:38] hesam at kolahan dot com
Description:
------------
The operator % can not calculate the following calculation:
Wrong calculation:
echo (16.49*100)%100; // prints 48 (should be 49)
Right calculations:
echo (13.49*100)%100; // prints 49
echo (14.49*100)%100; // prints 49
echo (15.49*100)%100; // prints 49
Test script:
---------------
echo "A wrong calculation:";
echo "<br>(16.49*100)%100 = ".((16.49*100)%100)." *By PHP";
echo "<br>(16.49*100)%100 = 1649%100 = 49 *By Hand";
echo "<br><br>A right calculation:";
echo "<br>(15.49*100)%100 = ".((15.49*100)%100)." *By PHP";
echo "<br>(15.49*100)%100 = 1549%100 = 49 *By Hand";
Expected result:
----------------
All results should be the same value (by hand == by PHP)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61580&edit=1