Another day, another bug. This one a rather nasty one in the x64 compiler.

Another day, another bug. This one a rather nasty one in the x64 compiler.

Consider this program:

{$APPTYPE CONSOLE}

uses
System.SysUtils;

var
D: Double;
begin
Writeln(fsZero=D.SpecialType);
Writeln(fsNZero=D.SpecialType);
D := -D;
Writeln(fsZero=D.SpecialType);
Writeln(fsNZero=D.SpecialType);
Readln;
end.

It should output

TRUE
FALSE
FALSE
TRUE

It does so on x86. On x64 it outputs

TRUE
FALSE
TRUE
FALSE

The reason being that Emba implemented floating point negation on x64 by compiling

-d

as

0 - d

Which is a different thing.

The right thing to do is to load the value into an XMM register, and then xor it with 8000000000000000h.

https://quality.embarcadero.com/browse/RSP-20350

That's three bugs in two days!
https://quality.embarcadero.com/browse/RSP-20350

Comments

  1. Purr math has infinitesimal numbers and has not machine epsylon. It can afford signless zero...

    ReplyDelete
  2. Arioch The I'm not actually sure that signed zero has proved its worth over the years. I think it lives on largely for historical reasons.

    ReplyDelete

Post a Comment