Hi Daniel, >> 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.
If you talk about 64 bit platforms, the 64 bit refers only to integers - not floats. There is no difference between the supported floating point types and operations of the most recent "32 bit" x86 processors and the newer "64 bit" x86_64 counterparts. Both have an i387 compatible FPU and both implement the SSE standard for vectorized floating point operations. SSE only supports single precision (23 + 8 + 1 = 32 bit) and double precision (52 + 11 + 1 = 64 bit) data types for vectorized operaitons. The i387 FPU supports single precision, double precision and a proprietary Intel "double extended" precision data type which uses 80 bits (actually only 79 are really necessary). Other processor architectures may only support single and double precision data types, yet others support some kind of "double double" precision which is a combination of two double precision values (total 128 bits) to support higher mantissa (but not higher exponent) and yet others support a real quad precision data type which has a larger mantissa and exponent. Some compilers allow the use of any of the above data types (Intel "double extended", "double-double", quad) via the »long double« C data type. Others (ESPECIALLY ALL the Microsoft compilers!) do not support »long double« but rather make »long double« be a normal double value. And for double-double data types the calculations are nearly always done with software emulation. So basically the situation is the following: You have 4 different possible data types for "long double" in C. Each with different mantissa and different exponent and 3 different sizes (64, 80 and 128 bit). To me, this sounds like hell. One of the changes I made in PHP 5.3 was actually to make sure *all* platforms use the normal IEEE double data type also for calculations. (there is something like "internal precision" in x87 compatible FPUs which makes life very complicated) This was done to ensure portability of the code. Because with floating point operations, even "simple" numbers (such as 0.01 or 1.0/3.0) cannot be exactly represented by a computer and thus every bit of the mantissa is required to approximate the number. If you then have different precisions on different platforms or even with different compilers, life gets complicated. For example, if you check that $a + $b >= $c on one system, this need not be true on another system if the precisions don't match - there are examples in both ways! So please, please, please: Don't complicate life and introduce "long double" in PHP. At least as long as there is no standardized >64 bit floating point data type that works across platforms and compilers. Regards, Christian -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php