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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.153.167 with SMTP id vh7mr9668274obb.5.1400743622738; Thu, 22 May 2014 00:27:02 -0700 (PDT) X-Received: by 10.140.93.23 with SMTP id c23mr17667qge.14.1400743622638; Thu, 22 May 2014 00:27:02 -0700 (PDT) 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!news.glorb.com!c1no13409144igq.0!news-out.google.com!qf4ni5721igc.0!nntp.google.com!c1no13409135igq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 22 May 2014 00:27:02 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=105.237.72.196; posting-account=orbgeAkAAADzWCTlruxuX_Ts4lIq8C5J NNTP-Posting-Host: 105.237.72.196 References: <3132e38d-18bb-4890-9cec-31056ac6e3ba@x19g2000prg.googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <83ce619a-beef-447f-91ef-ff3dd68ff9df@googlegroups.com> Subject: Re: How to check a Float for NaN From: jan.de.kruyf@gmail.com Injection-Date: Thu, 22 May 2014 07:27:02 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:19967 Date: 2014-05-22T00:27:02-07:00 List-Id: 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.