From: daseymour at 3hc dot org
Operating system: [Win 2000 SP4] and [Win XP SP1]
PHP version: 4.3.3
PHP Bug Type: Math related
Bug description: Float to String to Float conversion error
Description:
------------
When I convert a large float value to a string and then back to a float,
the original and the resulting values are not equal.
Note: I looked for this error in the bug list, but did not find one with
the current stable release of PHP (4.3.3).
Thanks in advance.
Reproduce code:
---------------
// Create some large number
$testStart = (float) unserialize("d:1125899906842624;");
// Output value
echo "Before string conversion: $testStart <br>\n";
// Convert value to string
$testString = (string) $testStart;
// Output string
echo "After string conversion: $testString <br>\n";
// Convert string back to a value
$testEnd = (float) $testString;
// Output value
echo "After float conversion: $testEnd <br>\n";
// Compare the two values
if( $testStart == $testEnd ) {
echo "<br>\nThe two values are equal.<br>\n";
} else {
echo "<br>\nThe two values appear to be the same, but are <u>not</u>
equal!<br>\n";
};
Expected result:
----------------
I expect to see "The two values are equal."
Actual result:
--------------
I am getting "The two values appear to be the same, but are not equal!"
--
Edit bug report at http://bugs.php.net/?id=25562&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25562&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25562&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=25562&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=25562&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=25562&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=25562&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=25562&r=support
Expected behavior: http://bugs.php.net/fix.php?id=25562&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=25562&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=25562&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=25562&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25562&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=25562&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=25562&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=25562&r=gnused