comp.lang.ada
 help / color / mirror / Atom feed
From: Jerry <lanceboyle@qwest.net>
Subject: Re: How to check a Float for NaN
Date: Wed, 30 Apr 2008 13:33:17 -0700 (PDT)
Date: 2008-04-30T13:33:17-07:00	[thread overview]
Message-ID: <e80b33a8-4b50-4bb3-96d9-bdfd7578922e@q27g2000prf.googlegroups.com> (raw)
In-Reply-To: 93b0d930-102a-4ac4-8b85-48e87d9d3df1@j33g2000pri.googlegroups.com

On Apr 30, 8:02 am, Adam Beneschan <a...@irvine.com> wrote:
> On Apr 30, 3:50 am, christoph.gr...@eurocopter.com wrote:
>
> > On 30 Apr., 12:47, christoph.gr...@eurocopter.com wrote:
>
> > > Try Float'Valid (X), see RM 13.9.2
>
> > Ahem, I meant X'Valid for X of type Float
>
> I'm not sure if this will produce the desired results, since it should
> return False for +/- infinity also.  That may be OK with the original
> poster, or not.
>
> The problem here is that if you're dealing with NaN's on purpose,
> you're not really dealing with Ada, as far as I can tell, unless your
> purpose is to test for an uninitialized variable (in which case
> X'Valid makes sense).  Otherwise, though, NaN's and infinities are not
> possible values of floating-point types, and therefore they can't be
> returned by operations that return floating-point values, even if
> Float'Machine_Overflows is False.  (There are certain passages in the
> RM that say a result is implementation-defined if the
> Machine_Overflows attribute is False; however, I do not think
> assigning a variable to an invalid value, as a NaN would be, is an
> allowed "implementation-defined" result.  13.9.2(4-11) lists the ways
> that invalid data could be created, and the "result of a floating-
> point operation that cannot return a valid result" is not one of those
> listed.  Yes, I know that this is a NOTE and is not normative.)
>
> Of course, if you compile with checking turned off or your code does
> something to turn off the floating-point overflow-checking bit in the
> processor (if there is one), you're outside the bounds of Ada, so you
> can't really come up with an Ada solution to the question, and
> whatever you do won't be portable.  In that case, "whatever works" is
> fine.  If I had to do this, I'd just do an Unchecked_Conversion to
> some data structure with a rep clause that represents an  IEEE-754
> float, or to a modular integer type or array of modular integer types,
> and then just test the bits myself.  Testing the 'Image for "NaN" will
> probably work, but if efficiency is a concern I wouldn't do this
> because if the float is a valid one, it's a *lot* of work to convert
> the float to a decimal representation, and that's especially painful
> here because you're just going to throw all that work out.
>
> P.S. Has the ARG or anyone discussed the possibility of building
> support for infinities and/or NaN's into the language---i.e. defining
> a floating-point type that includes those "values"?  G.1.1(56) makes
> me think that maybe there were some thoughts that this might be done
> sometime in the future, if there's a demand for it, but I could be
> reading something into this paragraph that isn't there.
>
>                                    -- Adam

Thanks for the insight. From my point of view, not having access to
the all the IEEE-754 features is a nuisance. I'm not sure what I'm
going to do--probably try in import the C function isnan. My need
isn't terribly important--just converting an example for PLplot that
is written in C. Frankly, I'm a little surprised that this isn't
handled by Ada--but I'm sure there's an excellent reason ;).

FWIW, I just now found this passage from the Annotated ARM at
http://www.adaic.org/standards/05aarm/html/AA-A-5-1.html, in A.5.1,
34.b (IEC 559 = IEEE 754):

"Discussion: It is anticipated that an Ada binding to IEC 559:1989
will be developed in the future. As part of such a binding, the
Machine_Overflows attribute of a conformant floating point type will
be specified to yield False, which will permit both the predefined
arithmetic operations and implementations of the elementary functions
to deliver signed infinities (and set the overflow flag defined by the
binding) instead of raising Constraint_Error in overflow situations,
when traps are disabled. Similarly, it is appropriate for the
elementary functions to deliver signed infinities (and set the zero-
divide flag defined by the binding) instead of raising
Constraint_Error at poles, when traps are disabled. Finally, such a
binding should also specify the behavior of the elementary functions,
when sensible, given parameters with infinite values."

Jerry





  reply	other threads:[~2008-04-30 20:33 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-30 10:27 How to check a Float for NaN Jerry
2008-04-30 10:47 ` christoph.grein
2008-04-30 10:50   ` christoph.grein
2008-04-30 15:02     ` Adam Beneschan
2008-04-30 20:33       ` Jerry [this message]
2008-04-30 23:23         ` Adam Beneschan
2008-05-01  1:00           ` Adam Beneschan
2008-05-01 19:52             ` Keith Thompson
2008-05-01 23:57               ` Jerry
2008-04-30 23:29       ` Randy Brukardt
2008-05-01  8:04       ` Stuart
2008-05-01 14:38         ` Adam Beneschan
2008-05-01 17:14           ` Stuart
2008-05-01 19:22             ` Randy Brukardt
2008-05-02  0:04         ` Jerry
2008-04-30 20:36 ` Jerry
2008-04-30 21:53   ` Adam Beneschan
2008-05-01  1:05     ` Jerry
2014-05-22  7:27   ` jan.de.kruyf
2014-05-22  8:09     ` Dmitry A. Kazakov
2014-05-22  9:24       ` Simon Wright
2014-05-22  9:48         ` Dmitry A. Kazakov
2014-05-22 15:28           ` Adam Beneschan
2014-05-22 16:31             ` Dmitry A. Kazakov
2014-05-22 23:33               ` Adam Beneschan
2014-05-23  7:38                 ` Dmitry A. Kazakov
2014-05-23 21:39                 ` Randy Brukardt
2014-05-27  8:35                   ` Dmitry A. Kazakov
2014-05-27 12:35                   ` Maurizio Tomasi
2014-05-27 15:53                     ` Adam Beneschan
2014-05-27 22:35                       ` Randy Brukardt
2014-05-27 22:59                         ` Jeffrey Carter
2014-05-28  7:32                         ` Dmitry A. Kazakov
2014-05-28  8:40                       ` Maurizio Tomasi
2008-05-05 18:23 ` Martin Krischik
2008-05-05 20:49   ` Adam Beneschan
2008-05-06 18:09     ` Jerry
2008-05-06 18:45       ` Wiljan Derks
2008-05-06 22:18         ` Adam Beneschan
2008-05-07 22:56           ` Randy Brukardt
2008-05-07 22:56           ` Randy Brukardt
2008-05-07 23:20             ` Adam Beneschan
2008-05-09  7:24             ` Stephen Leake
2008-05-10 17:00   ` anon
2008-05-11 22:00     ` Keith Thompson
2008-05-12  2:01       ` anon
2008-05-09 19:49 ` anon
2008-05-10  2:36   ` Jerry
2008-05-10  3:53     ` anon
2008-05-10  6:24       ` christoph.grein
2008-05-10  8:05     ` Georg Bauhaus
replies disabled

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