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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: How to check a Float for NaN Date: Thu, 22 May 2014 18:31:12 +0200 Organization: cbb software GmbH Message-ID: References: <3132e38d-18bb-4890-9cec-31056ac6e3ba@x19g2000prg.googlegroups.com> <83ce619a-beef-447f-91ef-ff3dd68ff9df@googlegroups.com> <3tso4mcv80hk.8j7e1grtnha0$.dlg@40tude.net> <6c8f74c9-4b4e-47a0-90e0-efa1ecdd5e2e@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: AuYlnUSfTZrfhAkRjyySpQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:19974 Date: 2014-05-22T18:31:12+02:00 List-Id: On Thu, 22 May 2014 08:28:33 -0700 (PDT), Adam Beneschan wrote: > On Thursday, May 22, 2014 2:48:47 AM UTC-7, Dmitry A. Kazakov wrote: >> On Thu, 22 May 2014 10:24:35 +0100, Simon Wright wrote: >> >>> "Dmitry A. Kazakov" writes: >> >>>> On Thu, 22 May 2014 00:27:02 -0700 (PDT), jan.de.kruyf 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 > >> Looks like a bug, it may not be optimized away if Long_Float is IEEE 754. > >>> inf.adb:10:60: warning: use 'Valid attribute instead > >> Hmm, reading RM 13.9.2 makes me believe that NaN's 'Valid should yield >> True. > > 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. Why doesn't it preclude NaN returned and accepted by arithmetic operations? Either 3.5.7 lies or the operations do. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de