Frank Heckenbach wrote:
Adriaan van Os wrote:
Wood David wrote:
However, is it really true that a floating point 0.0 isn't always all zero bytes?
In IEEE floating-point arthmetic "each floating point format (single, double and extended) has two representations for zero: +0 and -0. The two zeros compare as equal: +0= -0; however, their behaviors in the arithmetic are slightly different."
As the bit patterns for +0.0 and -0.0 must be different to distinguish between them, the answer to your question can only be "yes". Nevertheless, with IEEE floating-point formats a sequence of zero-bits will produce number +0.0.
I donÂt know if all platforms follow the IEEE-standard.
Nope.
You can test yourself easily. While writing such a test, I ran into an internal compiler error.
program zero; type int64 = integer( 64); var r: double; l: int64; begin l:= 0; int64( r):=l; writeln( 'r = ', r); r:= -1; double( l):= r; writeln( 'l = ', l) end.
[G4:~/gnu/testgpc/adriaan] adriaan% gpc -o zero zero.pas zero.pas: In main program: zero.pas:1: Internal compiler error in convert_move, at expr.c:507 Please submit a full bug report, with preprocessed source if appropriate. See URL:http://www.gnu-pascal.de/todo.html for instructions.
Thanks for the report (adriaan1.pas).
BTW, the test is questionable itself. It assumes 64 bit doubles which is true for IEEE, but not guaranteed at all for other formats. So better use `SizeOf' etc.
Besides, shouldn't that be:
begin l := 0; r := double(l); writeln('r = ', r); r := -1; l := int64(r); writeln('l = ', l) end.
i.e. the transform is applied to the right hand side. I would expect an error such as 'taking the address of an expression' with the original. Of course the compiler error should not happen.