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: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!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 11:48:47 +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> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: QTaafVZuunHujkJPndFR7g.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 X-Original-Bytes: 2324 Xref: number.nntp.dca.giganews.com comp.lang.ada:186560 Date: 2014-05-22T11:48:47+02:00 List-Id: 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@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 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. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de