Hello,
I just wanted to find out the status of bug 43053
(http://bugs.php.net/bug.php?id=43053) which is regarding inconsistent
handling of floating point numbers which seems to have changed in PHP 5.2.2
and later, but I don't see it documented nor see it listed on any changelog
or announcement. The problem is that certain floating point numbers are
being printed in scientific notation while others aren't - for example,
1200000.00 prints as 1.2E+6 while 1300000.00 prints as 1300000. In PHP
5.2.1 and earlier, 1200000.00 printed as 1200000. This then causes output
and validation issues since if the 1.2E+6 number is being passed somewhere
else, sprintf must be wrapped around it (e.g. echo'ed in the script, put in
a xml document validated against a schema, etc).
While I understand that the way floating point numbers are stored can vary
and shouldn't be relied upon, I'm more curious why a change was made in PHP
5.2.2 to print certain numbers in scientific notation, as it makes working
with floating point numbers much more difficult in PHP - in all previous
versions of PHP, these numbers were printed out in full form, not in
scientific notation.
Appreciate any help or feedback you could provide-
Thanks,
Ryan
While I understand that the way floating point numbers are stored can vary
and shouldn't be relied upon, I'm more curious why a change was made in PHP
5.2.2 to print certain numbers in scientific notation
In 5.2.1 string-to-double routines were changed to use BSD licensed
code (previous version was LGPLed).
What you see is just an unintentional side-effect of this update.
--
Wbr,
Antony Dovgal
Antony Dovgal wrote:
In 5.2.1 string-to-double routines were changed to use BSD licensed
code (previous version was LGPLed).
What you see is just an unintentional side-effect of this update.
Side-effect or not, it looks like the change was pretty major and some
documentation should be added. There, really, are two questions:
- What is the new behavior?
- Is the new behavior correct?
It looks like, from the bug report, two separate issues are being
reported. The first involves large integers, which I can't reproduce on
w32 builds for 5.2.2 and 5.2.5, and should have anything to do with
string-to-double. The second involves floats to strings.
I'd argue that the first case shouldn't be happening, and I don't see
it, but nate's report appears to be consistent with this sort of thing.
The float complaints, however, is almost certainly all bogus, and needs
better documentation.
--
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier http://htmlpurifier.org Anti-XSS Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
Antony Dovgal wrote:
In 5.2.1 string-to-double routines were changed to use BSD licensed
code (previous version was LGPLed).
Thanks, I first noticed this problem in 5.2.2 though. 5.2.1 does not
exhibit this behavior for me and works as I expected. Could the change be
caused by something else?
Ryan
Antony Dovgal wrote:
In 5.2.1 string-to-double routines were changed to use BSD licensed
code (previous version was LGPLed).
To follow-up on this, a patch was just posted in the bug for this issue. It
appears that the issue started with revision 1.30 to
ZendEngine2/zend_strtod.c in March 2007 and first appeared in PHP 5.2.2.
Would it be possible for someone to review the patch posted in the bug to
see if it can be included?
http://bugs.php.net/bug.php?id=43053
Thanks,
Ryan