From: jan.de.kruyf@gmail.com
Subject: Re: How to check a Float for NaN
Date: Thu, 22 May 2014 00:27:02 -0700 (PDT)
Date: 2014-05-22T00:27:02-07:00 [thread overview]
Message-ID: <83ce619a-beef-447f-91ef-ff3dd68ff9df@googlegroups.com> (raw)
In-Reply-To: <ddd4bca4-8d02-4ff0-8573-969ced71fd00@q27g2000prf.googlegroups.com>
On Wednesday, April 30, 2008 10:36:21 PM UTC+2, Jerry wrote:
>
> Check this out:
>
> function Is_NaN(x : Long_Float) return Boolean is
> begin
> return x /= x;
> end Is_NaN;
>
> A couple of minutes on Wikipedia saves the day. From
> http://en.wikipedia.org/wiki/NaN#NaN_encodings:
>
> "A NaN does not compare equal to any floating-point number or NaN,
> even if the latter has an identical representation. One can therefore
> test whether a variable has a NaN value by comparing it to itself."
>
> Jerry
This worked on the Gnat compiler, this code
if Cos_Theta /= Cos_Theta then
Gct.Trace (Debug_Str, "cos_theta is NaN******");
else
Gct.Trace (Debug_Str, "cos_theta : " & Long_Float'Image (Cos_Theta));
end if;
gives this in the log:
[MATH3D.DEBUG] 1/372 cos_theta is NaN****** (2014-05-22 09:23:24.155)(loc: math3d.adb:129)
Hope it helps someone;
Cheers,
j.
next prev parent reply other threads:[~2014-05-22 7:27 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 [this message]
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