Hi Dan,
----- Original Message -----
From: "Daniel Convissor"
Sent: Thursday, April 02, 2009
Hi Matt:
On Sat, Mar 14, 2009 at 09:30:42AM -0500, Matt Wilmas wrote:
But of course with
doubles, precision has been lost long before 2^63 anyway, as far as
increments of 1 (it's 1024 at 2^63).
I just ran into these issues in PHP 5.2.8 on 64 bit Linux while running
examples I'm using to improve our documentation surrounding bitwise
operators, bindec() and decbin().
The integer float conversions start failing above 2^53, meaning
9007199254740993 is the first integer that doesn't work. As you noted,
ints divisible by 1024 are fine. I can provide the test script to anyone
who needs it.
Sorry I didn't get back to you sooner, but unless I'm missing something,
you're talking about converting long/int to double/float. That's the
opposite of this thread subject, which is how to convert a double to a long
when it's out of the range of a long. :-)
But, for what you're testing, that's the behavior I'd expect -- once you've
reached the precision of a double, you'll only get the closest
representation possible (and of course a 64-bit long is more precise than a
double since there's no floating point to represent). Also, I assume what
can be represented by a double is the same across platforms, if it's IEEE
754.
Just curious though, you're saying that all whole numbers (from long) below
2^53 are representable? (Powers of 2 should always be OK.) When writing a
big literal number on a 32-bit system, I'm seeing much lower than that
(around 2^40), but in that case conversion is happening from a string,
digit-by-digit, instead of directly from a 64-bit integer type, so maybe
that's why...
A bash script I put together makes it look like things work correctly in
the shell. So it seems this is a PHP thing, not a Linux thing.
That's interesting, though I don't know much about shell script stuff (or
other *nix details ;-)). Like I said, I figure a double type should behave
the same everywhere. Unless the shell/bash uses a *long* double type (twice
as big as a regular double)? *shrug*
Am I correct in believing your changes will take care of these issues?
It seems you're looking to patch 5.3 and HEAD. Are there thoughts of
applying this to 5.2?
Thanks,
--Dan
Note: The guy who put the box together says everything on it is built
against 64 bit libraries.
- Matt
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php