Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-11

Nan values SIGFPE exception on 64 bit

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Birger Jansen

I encounter a strange difference in the behaviour of NaN values between windows 32 and 64 bit. Have a look at the following program:

-----------------------
program NanExample;
uses
  math;
var
  a, b, c: Double;
begin
  a := 0.0/0.0;
  b := 0.0/0.0;
  c := max(a,b);
  if IsNan(c) then
    WriteLn('NaN');
end.
-----------------------

On 32 bit this writes 'NaN' as expected. On 64 bit I get an SIGFPE exception on the max-function. Is there some specific compiler setting that I should be aware of to make this work on 64 bit?

Kind regards,
Birger Jansen

Jonas Maebe
to Birger Jansen
Birger Jansen wrote 24 lines
I encounter a strange difference in the behaviour of NaN values between windows 32 and 64 bit. Have a look at the following program: ----------------------- program NanExample; uses math; var a, b, c: Double; begin a := 0.0/0.0; b := 0.0/0.0; c := max(a,b); if IsNan(c) then WriteLn('NaN'); end. ----------------------- On 32 bit this writes 'NaN' as expected. On 64 bit I get an SIGFPE exception on the max-function. Is there some specific compiler setting that I should be aware of to make this work on 64 bit?

It should cause an exception everywhere by default (it does on PowerPC 32 bit). You have to use math.setexceptionmask if you want to mask exceptions for invalid floating point operations: http://www.freepascal.org/docs-html/rtl/math/setexceptionmask.html

Jonas