# bug 43053 - scientific notation

- Thread: https://externals.io/message/36123
- Original archive: https://news-web.php.net/php.internals/36123
- Started by Ryan Brothers on 2008-03-13T16:03:00+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #36123 — Ryan Brothers — 2008-03-13T16:03:00+00:00

URL: https://externals.io/message/36123#36123

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

---

## #36124 — Antony Dovgal — 2008-03-13T17:10:27+00:00

URL: https://externals.io/message/36123#36124 · In reply to: #36123

> 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

---

## #36128 — Edward Z. Yang — 2008-03-13T21:01:33+00:00

URL: https://externals.io/message/36123#36128 · In reply to: #36124

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:

1. What is the new behavior?
2. 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 ]]

---

## #36130 — Ryan Brothers — 2008-03-13T22:02:16+00:00

URL: https://externals.io/message/36123#36130 · In reply to: #36124

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

---

## #37157 — Ryan Brothers — 2008-04-21T15:07:06+00:00

URL: https://externals.io/message/36123#37157 · In reply to: #36130

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
