Bug #66132 [Opn->Nab]: X*5/X where X is floating point number is greater than 5
[email protected] Thu, 21 Nov 2013 14:41:11 GMT
| Newsgroups | php.gtk.dev |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=66132&edit=1 ID: 66132 Updated by: [email protected] Reported by: utilmind at gmail dot com Summary: X*5/X where X is floating point number is greater than 5 -Status: Open +Status: Not a bug Type: Bug Package: PHP-GTK related Operating System: Any, tested in Win32 and CentOS PHP Version: 5.4.22 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. php > ini_set("precision", 17); php > $n = (3.89880952381*5/3.89880952381); // result will be a very bit greater than 5 php > var_dump($n); float(5.0000000000000009) Previous Comments: ------------------------------------------------------------------------ [2013-11-21 00:19:36] [email protected] This is an PHP main package bug Confirmed Version: PHP 5.5.1-2 (built: Aug 5 2013 14:10:28) OS: Linux version 3.10-2-amd64 #1 SMP Debian 3.10.5-1 (2013-08-07) ------------------------------------------------------------------------ [2013-11-20 23:53:46] utilmind at gmail dot com Description: ------------ It's probably bug with conversion from floating point number, or bug with comparision between types. We know that X*5/5 is 5. Even PHP returns 5, however, sometimes, returned value appears to be greater than 5. Test script: --------------- $n = (3.89880952381*5/3.89880952381); // result will be exactly 5 print $n.'!=5 ? '.($n>5); // here it appears that 5 is greater than 5 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66132&edit=1