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-7-bit Path: g2news1.google.com!postnews.google.com!p25g2000pri.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: How to check a Float for NaN Date: Mon, 5 May 2008 13:49:25 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8ee4e946-786c-4faa-8c95-f9027083eb4b@p25g2000pri.googlegroups.com> References: <3132e38d-18bb-4890-9cec-31056ac6e3ba@x19g2000prg.googlegroups.com> <12227360.svS57WvVVs@linux1.krischik.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1210020566 20787 127.0.0.1 (5 May 2008 20:49:26 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 5 May 2008 20:49:26 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p25g2000pri.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:21187 Date: 2008-05-05T13:49:25-07:00 List-Id: 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 positive > 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: Is_NaN := (To_Unsigned_64(X) and not 2#1000_0000_0000_0000_0000_0000_0000_0000#) > 2#0111_1111_1111_0000_0000_0000_0000_0000#; But I haven't tried it. -- Adam