#25562 [Opn->Bgs]: Float to String to Float conversion error
| From: | helly@php.net | Date: | Tue, 16 Sep 2003 20:00:11 +0000 |
| Subject: | #25562 [Opn->Bgs]: Float to String to Float conversion error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-47661@lists.php.net to get a copy of this message | ||
ID: 25562
Updated by: helly@php.net
Reported By: daseymour at 3hc dot org
-Status: Open
+Status: Bogus
Bug Type: Math related
Operating System: [Win 2000 SP4] and [Win XP SP1]
PHP Version: 4.3.3
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Floating point values are handled with a limited precision.
Previous Comments:
------------------------------------------------------------------------
[2003-09-16 15:34:29] daseymour at 3hc dot org
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 this bug report at http://bugs.php.net/?id=25562&edit=1