Complier gives wrong value when assigning zero to single floating-point variables.
Original Reporter info from Mantis: babysam
-
Reporter name: Sam Cheng
Original Reporter info from Mantis: babysam
- Reporter name: Sam Cheng
Description:
When zero is assigned to a single variable, the value assigned to the variable is instead offset by a unknown amount.
Example:The following code gives 0.000001192E+00 instead of 0.000000000E+00
when excuted.
program try;
var foo:single;
begin
foo:=0.0;
writeln(foo);
readln;
end.
The error is persistent(regardless of the complier swithches) and offest is observed for both +ve and -ve values(-0.0 gives -0.000001192E+00).
Additional information:
It seems that the error is associated with the writeln() function (or something more fundamental) as the below code shows that the difference between 0.0(single variable) and 0(longword) is zero.
program try;
var foo:single;
bar,off:longword;
begin
foo:=0.0;
bar:=0;
writeln(foo);
writeln(bar);
asm
mov edx,foo
sub edx,bar
mov off,edx
end;
writeln(off);
readln;
end.
The program show the following when +0.0 is assigned to foo
foo=0.000001192E+00
bar=0
off=0
and these when -0.0 is assigned instead
foo=-0.000001192E+00
bar=0
off=2147483648
Mantis conversion info:
- Mantis ID: 12202
- Version: 2.2.2
- Fixed in version: 2.2.4
- Fixed in revision: 12151 (#8ed06a05)