Sign in Join

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

Mailing lists / fpc-pascal / 2007-01

NAN for double

10 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Mattias Gaertner

How to set a double to NAN (not a number)?
I only found a IsNAN in the math unit.

Mattias

Mattias Gaertner
to Daniël Mantione
Show quoted text 8 lines
Op Thu, 25 Jan 2007, schreef Mattias Gaertner: > How to set a double to NAN (not a number)? > I only found a IsNAN in the math unit. const nan=0/0;
unit1.pas(28,10) Error: Division by zero

Mattias

Marco van de Voort
to Mattias Gaertner
Show quoted text 6 lines
> > How to set a double to NAN (not a number)? > > I only found a IsNAN in the math unit. > > const nan=0/0; unit1.pas(28,10) Error: Division by zero

Afaik that is delphi mode only. Also check the "typ" unit of numlib (in packages)

Mattias Gaertner
to Marco van de Voort
Show quoted text 8 lines
> > > How to set a double to NAN (not a number)? > > > I only found a IsNAN in the math unit. > > > > const nan=0/0; > > unit1.pas(28,10) Error: Division by zero Afaik that is delphi mode only.

Me delphi mode? Are you kidding?

Also check the "typ" unit of numlib (in packages)

Thanks.

const
  NANDoubleArray : ARRAY[0..7] OF BYTE = ($FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF);
var
  nan : double absolute NANDoubleArray;

Maybe NAN constants for float types can be added to the Math unit?

Mattias

Marco van de Voort
to Mattias Gaertner
Show quoted text 11 lines
On Thu, 25 Jan 2007 12:51:06 +0100 (CET) (Marco van de Voort) wrote: > Also check the "typ" unit of numlib (in packages) Thanks. const NANDoubleArray : ARRAY[0..7] OF BYTE = ($FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF); var nan : double absolute NANDoubleArray;

(note this was never endian checked)

Daniël Mantione
to Mattias Gaertner: On Thu, 25 Jan 2007 12:10:44 +0100 (CET) unit1.pas(28,10) Error: Division by zero Mattias

Op Thu, 25 Jan 2007, schreef Mattias Gaertner:

Show quoted text 13 lines
On Thu, 25 Jan 2007 12:10:44 +0100 (CET) Daniël Mantione wrote: > > > Op Thu, 25 Jan 2007, schreef Mattias Gaertner: > > > How to set a double to NAN (not a number)? > > I only found a IsNAN in the math unit. > > const nan=0/0; unit1.pas(28,10) Error: Division by zero

Well, not here. See the program below. Can you check if this depends on the compiler version or mode? 0/0 should normally work.

Daniël

cat nan.pas
program nan;
const _nan=0/0;
begin
  writeln(_nan);
end.
ppc386 nan

Free Pascal Compiler version 2.0.4 [2006/08/20] for i386 Copyright (c) 1993-2006 by Florian Klaempfl
Target OS: Linux for i386
Compiling nan.pas
Linking nan
7 Lines compiled, 0.0 sec

./nan

Nan

Mattias Gaertner
to Florian Klaempfl
Show quoted text 5 lines
Mattias Gaertner schrieb: > How to set a double to NAN (not a number)? > I only found a IsNAN in the math unit. Then you should search more ;) Acutally there is NaN

You are right. Sorry, probably a typo in the search. FPC is great.

Mattias

Mattias Gaertner
to Daniël Mantione: Op Thu, 25 Jan 2007, schreef Mattias Gaertner: Well, not here. See the program below. Can…
Show quoted text 20 lines
Op Thu, 25 Jan 2007, schreef Mattias Gaertner: > On Thu, 25 Jan 2007 12:10:44 +0100 (CET) > Daniël Mantione wrote: > > > > > > > Op Thu, 25 Jan 2007, schreef Mattias Gaertner: > > > > > How to set a double to NAN (not a number)? > > > I only found a IsNAN in the math unit. > > > > const nan=0/0; > > unit1.pas(28,10) Error: Division by zero Well, not here. See the program below. Can you check if this depends on the compiler version or mode? 0/0 should normally work.

It depends on -Cr.

Mattias