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!news1.google.com!postnews.google.com!l28g2000prd.googlegroups.com!not-for-mail From: Jerry Newsgroups: comp.lang.ada Subject: Re: How to check a Float for NaN Date: Tue, 6 May 2008 11:09:56 -0700 (PDT) Organization: http://groups.google.com Message-ID: <97217ff4-aaf3-41ed-986c-8b6c0954e112@l28g2000prd.googlegroups.com> References: <3132e38d-18bb-4890-9cec-31056ac6e3ba@x19g2000prg.googlegroups.com> <12227360.svS57WvVVs@linux1.krischik.com> <8ee4e946-786c-4faa-8c95-f9027083eb4b@p25g2000pri.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 1210097396 26444 127.0.0.1 (6 May 2008 18:09:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 6 May 2008 18:09:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l28g2000prd.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.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:21191 Date: 2008-05-06T11:09:56-07:00 List-Id: On May 5, 1:49=A0pm, Adam Beneschan wrote: > On May 5, 11:23 am, Martin Krischik > wrote: > > > 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). > > > How about an Unchecked Conversion to an Unsigned_64 and comparing > > > >2#0111_1111_1111_0000_0000_0000_0000_0000# > > > Note that it's '>' as 2#0111_1111_1111_0000_0000_0000_0000_0000# is posi= tive > > infinity. > > Any negative float (including negative infinity) would be > than the > binary number you give, since the leftmost bit (sign bit) would be 1. > I think you need to clear the sign bit first, then your comparison > will work: > > =A0 Is_NaN :=3D (To_Unsigned_64(X) and not > =A0 =A0 =A0 =A0 =A0 =A0 =A0 2#1000_0000_0000_0000_0000_0000_0000_0000#) > =A0 =A0 =A0 =A0 =A0 =A0 =A0> 2#0111_1111_1111_0000_0000_0000_0000_0000#; > > But I haven't tried it. > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- Ada= m I thought about doing something like this once I saw the bit patterns on the Wikipedia page. However, I would guess that the bit pattern for quiet and signaling NaNs is different, so the test would be somewhat more complicated if one wanted to detect both types. Jerry