Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: How to chec...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 35 Topic 5676 of 5827
Post > Topic >>

Re: How to check a Float for NaN

by Jerry <lanceboyle@[EMAIL PROTECTED] > Apr 30, 2008 at 01:33 PM

On Apr 30, 8:02=A0am, Adam Beneschan <a...@[EMAIL PROTECTED]
> wrote:
> On Apr 30, 3:50 am, christoph.gr...@[EMAIL PROTECTED]
 wrote:
>
> > On 30 Apr., 12:47, christoph.gr...@[EMAIL PROTECTED]
 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. =A0That 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). =A0Otherwise, 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. =A0(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. =A013.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. =A0Yes, 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 ****table. =A0In that case, "whatever works" is
> fine. =A0If I had to do this, I'd just do an Unchecked_Conversion to
> some data structure with a rep clause that represents an =A0IEEE-754
> float, or to a modular integer type or array of modular integer types,
> and then just test the bits myself. =A0Testing 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
> sup****t for infinities and/or NaN's into the language---i.e. defining
> a floating-point type that includes those "values"? =A0G.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.
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
=A0-- =
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 im****t the C function isnan. My need
isn't terribly im****tant--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 =3D 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
 




 35 Posts in Topic:
How to check a Float for NaN
Jerry <lanceboyle@[EMA  2008-04-30 03:27:51 
Re: How to check a Float for NaN
christoph.grein@[EMAIL PR  2008-04-30 03:47:54 
Re: How to check a Float for NaN
christoph.grein@[EMAIL PR  2008-04-30 03:50:15 
Re: How to check a Float for NaN
Adam Beneschan <adam@[  2008-04-30 08:02:05 
Re: How to check a Float for NaN
"Randy Brukardt"  2008-04-30 18:29:14 
Re: How to check a Float for NaN
"Stuart" <st  2008-05-01 09:04:11 
Re: How to check a Float for NaN
Jerry <lanceboyle@[EMA  2008-04-30 13:33:17 
Re: How to check a Float for NaN
Jerry <lanceboyle@[EMA  2008-04-30 13:36:21 
Re: How to check a Float for NaN
Adam Beneschan <adam@[  2008-04-30 14:53:54 
Re: How to check a Float for NaN
Adam Beneschan <adam@[  2008-04-30 16:23:13 
Re: How to check a Float for NaN
Adam Beneschan <adam@[  2008-04-30 18:00:21 
Re: How to check a Float for NaN
Keith Thompson <kst-u@  2008-05-01 12:52:16 
Re: How to check a Float for NaN
Jerry <lanceboyle@[EMA  2008-04-30 18:05:41 
Re: How to check a Float for NaN
Adam Beneschan <adam@[  2008-05-01 07:38:40 
Re: How to check a Float for NaN
"Stuart" <st  2008-05-01 18:14:09 
Re: How to check a Float for NaN
"Randy Brukardt"  2008-05-01 14:22:35 
Re: How to check a Float for NaN
Jerry <lanceboyle@[EMA  2008-05-01 16:57:26 
Re: How to check a Float for NaN
Jerry <lanceboyle@[EMA  2008-05-01 17:04:53 
Re: How to check a Float for NaN
Martin Krischik <krisc  2008-05-05 20:23:02 
Re: How to check a Float for NaN
anon@[EMAIL PROTECTED] (  2008-05-10 17:00:51 
Re: How to check a Float for NaN
Keith Thompson <kst-u@  2008-05-11 15:00:55 
Re: How to check a Float for NaN
anon@[EMAIL PROTECTED] (  2008-05-12 02:01:18 
Re: How to check a Float for NaN
Adam Beneschan <adam@[  2008-05-05 13:49:25 
Re: How to check a Float for NaN
Jerry <lanceboyle@[EMA  2008-05-06 11:09:56 
Re: How to check a Float for NaN
"Wiljan Derks"   2008-05-06 20:45:47 
Re: How to check a Float for NaN
Adam Beneschan <adam@[  2008-05-06 15:18:39 
Re: How to check a Float for NaN
"Randy Brukardt"  2008-05-07 17:56:57 
Re: How to check a Float for NaN
Stephen Leake <Stephe.  2008-05-09 03:24:21 
Re: How to check a Float for NaN
"Randy Brukardt"  2008-05-07 17:56:57 
Re: How to check a Float for NaN
Adam Beneschan <adam@[  2008-05-07 16:20:55 
Re: How to check a Float for NaN
anon@[EMAIL PROTECTED] (  2008-05-09 19:49:50 
Re: How to check a Float for NaN
Jerry <lanceboyle@[EMA  2008-05-09 19:36:58 
Re: How to check a Float for NaN
anon@[EMAIL PROTECTED] (  2008-05-10 03:53:54 
Re: How to check a Float for NaN
Georg Bauhaus <see.rep  2008-05-10 10:05:33 
Re: How to check a Float for NaN
christoph.grein@[EMAIL PR  2008-05-09 23:24:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 0:03:41 CDT 2008.