From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: How to check a Float for NaN Date: Thu, 22 May 2014 10:24:35 +0100 Organization: A noiseless patient Spider Message-ID: References: <3132e38d-18bb-4890-9cec-31056ac6e3ba@x19g2000prg.googlegroups.com> <83ce619a-beef-447f-91ef-ff3dd68ff9df@googlegroups.com> <3tso4mcv80hk.8j7e1grtnha0$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="f944b7aa56b4100b8770465c51f11294"; logging-data="2649"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VBpLf2zGOfCdN6xrMXyGqWrIsUkRp174=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:i4aSH7PsbcJjtM52G/B3YMrDuE8= sha1:NUqccyuQL1qL1uRgxg+5woVI+Q4= Xref: news.eternal-september.org comp.lang.ada:19969 Date: 2014-05-22T10:24:35+01:00 List-Id: "Dmitry A. Kazakov" writes: > On Thu, 22 May 2014 00:27:02 -0700 (PDT), jan.de.kruyf@gmail.com wrote: >> 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; > > You could simply use range check: > > X in Long_Float'Range > > NaN is not a number and thus outside the range. This would also return False for +/-Inf, so if the OP wants specifically to check for NaN it wouldn't do. Can't think why they would, though. GNAT says about "X in Long_Float'Range" inf.adb:10:60: warning: explicit membership test may be optimized away inf.adb:10:60: warning: use 'Valid attribute instead