Req #42635 [Com]: var_dump() should render more precise floats
Edit report at https://bugs.php.net/bug.php?id=42635&edit=1
ID: 42635
Comment by: jan dot kahoun at heureka dot cz
Reported by: daniel dot oconnor at gmail dot com
Summary: var_dump() should render more precise floats
Status: Open
Type: Feature/Change Request
Package: Feature/Change Request
Operating System: Irrelevant
PHP Version: 5.2.4
Block user comment: N
Private report: N
New Comment:
This bug is really annoying! I spend lot of time to find, that var_dump is rounding float values. It
was reported 6 year ago, why this was not fixed yet?
Previous Comments:
------------------------------------------------------------------------
[2007-09-12 03:31:50] daniel dot oconnor at gmail dot com
Description:
------------
var_dump() does not show the actual value of floats; but rather performs rounding before rendering.
This can lead to hard to decipher loss of precision bugs. If you then use var_dump() to try to
compare output, you aren't going to find the *actual* values of the numbers you are comparing.
For this reason, I'd like to ask var_dump() renders the complete representation of the number;
where needed in scientific notation.
Reproduce code:
---------------
<?php
function variance($a, $b) {
return (double)100.00 - (double)(($a/$b) * 100.00);
}
var_dump(12.99); //12.99
var_dump(variance(87.01, 100.00)); //12.99
var_dump(variance(87.01, 100.00) - 12.99); //difference <-5.3290705182008E-15>
Expected result:
----------------
---------- php ----------
float(12.99)
float(12.99) // should be 12.99 + -5.3290705182008E-15
float(-5.3290705182008E-15)
Output completed (0 sec consumed) - Normal Termination
Actual result:
--------------
---------- php ----------
float(12.99)
float(12.99)
float(-5.3290705182008E-15)
Output completed (0 sec consumed) - Normal Termination
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=42635&edit=1
Thread (4 messages)