comp.lang.ada
 help / color / mirror / Atom feed
From: Warren <ve3wwg@gmail.com>
Subject: Re: S'Is_nan or S'Is_inf?
Date: Fri, 16 Jul 2010 22:35:14 +0000 (UTC)
Date: 2010-07-16T22:35:14+00:00	[thread overview]
Message-ID: <Xns9DB7BD155A072WarrensBlatherings@81.169.183.62> (raw)
In-Reply-To: 1tbp3geoa5yna$.171cmlfdrbm98$.dlg@40tude.net

Dmitry A. Kazakov expounded in
news:1tbp3geoa5yna$.171cmlfdrbm98$.dlg@40tude.net: 

> with Ada.Text_IO;  use Ada.Text_IO;
> procedure IEEE is -- Only if Float is IEEE!
>    Zero : Float := 0.0;
>    Inf  : Float := 1.0 / Zero;
>    NaN  : Float := 0.0 / Zero;
> begin
>    Put_Line ("Valid    " & Boolean'Image (Inf'Valid));
>    Put_Line ("In range " & Boolean'Image (Inf <= Float'Last));
>    Put_Line ("Self NaN " & Boolean'Image (NaN = NaN));
> end IEEE;
> 
> On an IEEE machine it could print 3x FALSE.

To detect NaN then, this seems to work:

    function Is_Nan(F : Float) return Boolean is
    begin
        if not F'Valid then
            return not ( Is_Infinity(F) or Is_Neg_Infinity(F) );   
        else
            return False;
        end if;
    end Is_Nan;

where Is_Infinity(F) etc. is implemented as suggested. Essentially
if not valid, but not one of the infinities(+ or -), then it 
must be NaN. This works with Gnat on Cygwin. I'll need
to test it on other platforms, but hopefully most if not all
IEEE platforms will support this.

Warren



  parent reply	other threads:[~2010-07-16 22:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-15 21:00 S'Is_nan or S'Is_inf? Warren
2010-07-15 21:30 ` Rod Chapman
2010-07-15 22:03   ` Simon Wright
2010-07-15 21:42 ` J-P. Rosen
2010-07-15 22:07 ` Simon Wright
2010-07-16  8:42   ` Dmitry A. Kazakov
2010-07-16 17:06     ` Warren
2010-07-16 19:39       ` Dmitry A. Kazakov
2010-07-16 22:35     ` Warren [this message]
2010-07-17  6:24       ` Simon Wright
2010-07-19 17:04         ` Warren
2010-07-17  7:40       ` Dmitry A. Kazakov
2010-07-19 17:18         ` Warren
2010-07-19 23:15 ` Randy Brukardt
2010-07-20 14:12   ` Warren
2010-07-20 16:20     ` Dmitry A. Kazakov
replies disabled

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