comp.lang.ada
 help / color / mirror / Atom feed
From: Maurizio Tomasi <ziotom78@gmail.com>
Subject: Re: How to check a Float for NaN
Date: Tue, 27 May 2014 05:35:26 -0700 (PDT)
Date: 2014-05-27T05:35:26-07:00	[thread overview]
Message-ID: <a71ebb05-974e-4df3-87ff-bdaca4db50fa@googlegroups.com> (raw)
In-Reply-To: <lm06os$b58$2@loke.gir.dk>

> That is, I see no sensible reason for NaNs or infinities -- they're just ways of deferring detection of bugs. I would have hoped that Ada's moved beyond that, just like it has for integers.]

Being a scientist working with large chunks of data, I find NaNs useful in a number of situations. I work in a domain (observational cosmology) where we need to deal with sky maps containing ~10^7 pixels (you can think of a "map" as a 1D vector where pixels on the sky sphere are ordered according to some rule). Not every sky direction can be sampled, because of a number of problems (in the instrument, in the observational strategy, in the data reduction pipeline, etc.)

Therefore, in my Python+NumPy codes I always mark such directions using "quiet NaNs". If I have to combine two maps in order e.g. to take their average, the usual rules for combining NaNs are be exactly what I want. Writing in Ada what I actually write in Python:

  for I := 1 to N do
    Average_Map(I) := 0.5 * (Map1(I) + Map2(I));
  end loop;

If either Map1(I) or Map2(I) (or both) are NaN, then Average_Map(I) will be a NaN too, which is correct from the point of view of the meaning of the measurement. But without proper treatment of NaNs, one should write

  for I in Map1'Range do
    if not Is_NaN(Map1(I)) and not Is_NaN(Map2(I)) then
      Average_Map(I) := 0.5 * (Map1(I) + Map2(I));
    else
      Set_To_NaN(Average_Map, I);
    end if;
  end loop;

If one has to run many calculations on such maps (which is indeed always the case) instead of just a plain average, the code can get quite complex. And I do not think one gets more safety from such verbosity, as what a scientist expects from a NaN number is actually what the usual rules for NaN give.

I am not an Ada export, so these are just my two cents,
  Maurizio.


  parent reply	other threads:[~2014-05-27 12:35 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
2014-05-23 21:39                 ` Randy Brukardt
2014-05-27  8:35                   ` Dmitry A. Kazakov
2014-05-27 12:35                   ` Maurizio Tomasi [this message]
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