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 X-Google-Thread: 103376,772ddcb41cd06d5b X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Sat, 10 May 2008 10:05:33 +0200 From: Georg Bauhaus Reply-To: rm.tsho+bauhaus@maps.futureapps.de User-Agent: Thunderbird 2.0.0.14 (X11/20080502) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How to check a Float for NaN References: <3132e38d-18bb-4890-9cec-31056ac6e3ba@x19g2000prg.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4825574d$0$7547$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 10 May 2008 10:05:33 CEST NNTP-Posting-Host: 1966d19b.newsspool1.arcor-online.net X-Trace: DXC=f]Za;JHBoLL78PK[oJ2ng@ic==]BZ:afN4Fo<]lROoRA<`=YMgDjhgBLkNlRKiA?OHPCY\c7>ejVHc Jerry wrote: > On May 9, 12:49 pm, a...@anon.org (anon) wrote: >> -- >> -- Nan is define to be greater than value of hex 16#FF000000# >> -- >> >> function isNan ( N : Float ) return Boolean is >> >> T : Long_Long_Integer := Long_Long_Integer ( N ) ; >> >> begin >> if T > 16#FF000000# then >> return True ; >> else >> return False ; >> end if ; >> end ; >> > No offense to anon, but does this work? Does anyone know of a > reference for this definition of a NaN? > > Also, wondering how one might detect an Inf. > > It seems that there is enough information in this thread to begin > writing a little package to deal with some of these things. I think you will need IEEE floats, not just Ada Floats. (Some compilers have corresponding types, or implement their Floats accordingly.) Consulting a text book again, I find that IEEE defines representations for NaN (both quiet and signalling NaN), Inf, ... IIUC, for testing for NaN, basically - ignore the sign bit - expect all exponent bits set to 1 - expect the fraction part to be /= 0 This would explain why there are cases when an unchecked_conversion of an IEEE FPT word to some "scalar word" will allow you to look at the bits and decide whether it can represents a NaN. Showing my ignorance I wonder, though, what happens when a fpt register is effectively unchecked_converted into a CPU register suitable for a long...