comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Catching NaN .. not a number
Date: Mon, 7 May 2001 20:37:33 -0500
Date: 2001-05-07T20:37:33-05:00	[thread overview]
Message-ID: <u5IJ6.11316$R2.10584546@newsrump.sjc.telocity.net> (raw)
In-Reply-To: uelu0on1n.fsf@gsfc.nasa.gov

As I posted Saturday, May 5:

Catching NaN requires a three-way test, viz.:

if Value /= 0.0 and then (not (Value < 0.0)) and then (not (Value > 0.0))
then
   <Value is NaN>;
end if;

"Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
news:uelu0on1n.fsf@gsfc.nasa.gov...
> Keith Thompson <kst@cts.com> writes:
>
> > f97stdi@dd.chalmers.se (Staffan Dittmer) writes:
> > > Did some calcualtions during the night and
> > > ended up with an output file full of NaN - due to
> > > overflow when calculating a factorial.
> > >
> > > A bit surprised by this since I thought a Constraint Error
> > > would be raised.
> >
> > An implementation isn't required to raise Constraint_Error on
> > floating-point overflow or division by zero.  See the
> > Machine_Overflows attribute.
> >
> > > So, how do I catch a NaN result ?
> >
> > I don't think there's a standard way to do so; see the documentation
> > for your implementation.
>
> X'Valid should catch it; see ARM 13.9.2
>
> And it works in GNAT 3.14a:
>
> with Ada.Text_IO; use Ada.Text_IO;
> procedure NAN
> is
>    Zero : Float := 0.0;
>    A_NAN : Float := 1.0 / Zero;
> begin
>   Put_Line ("A_NAN'Valid => " & Boolean'Image (A_Nan'Valid));
> end NAN;
>
> generates:
>
> A_NAN'Valid => FALSE
>
> --
> -- Stephe




      reply	other threads:[~2001-05-08  1:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-05 17:46 Catching NaN .. not a number Staffan Dittmer
2001-05-05 17:58 ` Preben Randhol
2001-05-05 18:28   ` Staffan Dittmer
2001-05-05 21:50 ` Keith Thompson
2001-05-07 21:40   ` Stephen Leake
2001-05-08  1:37     ` David C. Hoos, Sr. [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox