Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trunc() fails for high Int64 for 64-bit builds

Tags:

64-bit

delphi

Why does the following code fail for 64-bit builds (but works for 32-bit builds)?

var
  TruncTmp: Extended;
begin
  TruncTmp := 9223372036854775296;
  TruncTmp := Trunc(TruncTmp); // this fails on 64-bit
  Assert(TruncTmp = 9223372036854775296);
end;

First chance exception at $0000000000405D70. Exception class $C0000090 with message 'c0000090 FLOAT_INVALID_OPERATION'.

Is this a bug or am I missing something?

Notes:

  • I am using Delphi 10.2
  • Numbers < 9223372036854775296 work fine
like image 477
TmTron Avatar asked Dec 14 '22 18:12

TmTron


1 Answers

There is no "extended" (80-bit FP) type under Win64 - it is just an alias to "double" (64-bit FP). So you only have 53-bit of resolution in double.

So my guess it is that is as expected in your case.

like image 72
Arnaud Bouchez Avatar answered Dec 29 '22 02:12

Arnaud Bouchez