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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,772ddcb41cd06d5b X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!q27g2000prf.googlegroups.com!not-for-mail From: Jerry Newsgroups: comp.lang.ada Subject: Re: How to check a Float for NaN Date: Wed, 30 Apr 2008 13:36:21 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <3132e38d-18bb-4890-9cec-31056ac6e3ba@x19g2000prg.googlegroups.com> NNTP-Posting-Host: 75.171.61.127 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1209587781 26612 127.0.0.1 (30 Apr 2008 20:36:21 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 30 Apr 2008 20:36:21 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: q27g2000prf.googlegroups.com; posting-host=75.171.61.127; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.13 (KHTML, like Gecko) Version/3.1 Safari/525.13,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:21149 Date: 2008-04-30T13:36:21-07:00 List-Id: On Apr 30, 3:27=A0am, Jerry wrote: > How would one check a Float or Long_Float if it has value NaN? The > only ways that I can come up with are to import a C function (isnan, I > think) or to write Long_Float'image(Some_Float) to a string and > examine the first three characters to see if they are "NaN" (and that > seems to be a GNAT implementation choice so might not be portable, > which is OK for my use). > > Jerry Check this out: function Is_NaN(x : Long_Float) return Boolean is begin return x /=3D 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