Hi Matt, and everyone: On Mon, Apr 06, 2009 at 01:00:47PM -0500, Matt Wilmas wrote:
> 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. :-) It's a two way street. If the floats don't have enough precision, things get jumbled when converting the floats back to integers. > 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. Yes. But I was expecting that since long on 64-bit machines holds 64 bits in PHP (et al), that PHP would use C's long double type for floats on 64-bit platforms rather than plain old doubles. It seems like the user-friendly, PHP way to handle the situation, particularly as 64-bit computers are commonplace these days. > 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) I'm talking about 64-bit machines. > 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* Exactly. The test scripts in question are now available for download from http://www.analysisandsolutions.com/php/intfloat/ Thanks, --Dan -- T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y data intensive web and database programming http://www.AnalysisAndSolutions.com/ 4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php