comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: How to check a Float for NaN
Date: Fri, 23 May 2014 09:38:58 +0200
Date: 2014-05-23T09:38:58+02:00	[thread overview]
Message-ID: <1vwho0j33rn0v.1bw5jk59v7f7z.dlg@40tude.net> (raw)
In-Reply-To: b96fb365-9061-4170-8824-f68bab37f9dc@googlegroups.com

On Thu, 22 May 2014 16:33:50 -0700 (PDT), Adam Beneschan wrote:

> On Thursday, May 22, 2014 9:31:12 AM UTC-7, Dmitry A. Kazakov wrote:
> 
>>> No, I don't think so.  3.5.7(8) says "The set of values for a floating
>>> point type is the (infinite) set of rational numbers."  This excludes NaN
>>> and infinities, which are not rational numbers (nor any kind of number).
>> 
>> These are not values of Long_Float. I guess that values of Long_Float are
>> "machine numbers" defined in the following sentence.
> 
> I'm not sure why the RM defined the "set of values" to be an infinite set;
> I'm sure that this made the rest of the semantics easier to specify in
> some way, but I don't know what that is.  The set of *machine numbers* for
> a type is a subset of this set of values.  I think that intermediate
> computations can involve numbers that aren't machine numbers (if they're
> performed using a type with greater precision, for example); I'm not sure. 
> In any case, though, it's clear that infinities and NaN aren't part of the
> "set of values", and thus they can't be part of the set of machine numbers
> which is a subset of the "set of values".

Yes, but NaN is certainly a machine value of IEEE 754 hardware.

My impression is that the text was written prior to wide spread of IEEE 754
hardware and was not reviewed since.

>> Why doesn't it preclude NaN returned and accepted by arithmetic operations? 
>> Either 3.5.7 lies or the operations do.
> 
> I think it *does* preclude NaN, unless I don't understand what you mean. 
> I guess you could say that the "operations lie", because if
> Machine_Overflows is False, an operation on two values of a floating-point
> type may have an invalid result.

Yes, but an invalid result still may not be outside the set of type values!

If NaN is not a type value, then an operation returning NaN is not of the
type. It is a type error then, a compiler/language bug.

After all, floating-point types are models, there is no reason why a model
could not have ideals NaN, +/-Inf as proper values and thus arithmetic
operations were defined in terms of this extended set of values. Which is
what IEEE 754 actually is all about.

The semantics of X'Value to exclude IEEE ideals could be easily defined in
13.9.2 as a special case. (X'Succ and X'Pred are already defined correctly
as returning a machine number.)

3.5.7 could be slightly rewritten to convey that type values include
equivalents of some real numbers (machine numbers) and, possibly, of some
ideals (machine special values).

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


  reply	other threads:[~2014-05-23  7:38 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
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 [this message]
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 23:20             ` Adam Beneschan
2008-05-09  7:24             ` Stephen Leake
2008-05-07 22:56           ` Randy Brukardt
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