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!y22g2000prd.googlegroups.com!not-for-mail From: Jerry Newsgroups: comp.lang.ada Subject: Re: How to check a Float for NaN Date: Thu, 1 May 2008 16:57:26 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <3132e38d-18bb-4890-9cec-31056ac6e3ba@x19g2000prg.googlegroups.com> <6f7cd771-16b7-4729-9536-2a7d1c28a9cd@2g2000hsn.googlegroups.com> <93b0d930-102a-4ac4-8b85-48e87d9d3df1@j33g2000pri.googlegroups.com> <1216f027-8fa4-45df-9b84-ae387164505b@p25g2000pri.googlegroups.com> <87ve1xztsf.fsf@kvetch.smov.org> 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 1209686248 1302 127.0.0.1 (1 May 2008 23:57:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 1 May 2008 23:57:28 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: y22g2000prd.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:21170 Date: 2008-05-01T16:57:26-07:00 List-Id: On May 1, 12:52=A0pm, Keith Thompson wrote: > Adam Beneschan writes: > > On Apr 30, 4:23 pm, I wrote: > >> On Apr 30, 1:33 pm, Jerry wrote: > >> > Thanks for the insight. From my point of view, not having access to > >> > the all the IEEE-754 features is a nuisance. I'm not sure what I'm > >> > going to do--probably try in import the C function isnan. > > >> Be careful with that, too. =A0On my (Pentium Linux) system, the man pag= e > >> for "isnan" says it takes a "double", which I think means a 64-bit > >> float. > > > Ha, ha, ha, the man page lied. =A0Apparently (on my system) isnan is a C= > > macro (in ), which will call one of three routines depending > > on the size of the float. =A0But since isnan is a macro, doing an Import= > > pragma on it is likely going to fail since "isnan" is not the name of > > an actual routine in the library. =A0That's on my OS, though; who knows > > how it works on yours. > > > Anyway, good luck and have fun getting this to work. > > The C99 C standard (which is not widely implemented, at least not > completely) specifies that isnan() is a macro that can take an > argument of any floating-point type (float, double, long double). =A0It > might typically be implemented by invoking one of three functions > depending on the size of the argument, but the standard doesn't > specify any particular method; it could be pure magic. =A0The earlier > C90 standard doesn't provide any such floating-point classification > macros or functions. =A0Some C90 implementations might provide a > function, rather than macro, called "isnan"; perhaps that's what your > system documents. > > You can't interface to a C macro from Ada (as far as I know), but you > can easily write a wrapper function. =A0Assuming your C implementation > provides the isnan() macro as specified by C99, you can do this: > > =A0 =A0 #include > > =A0 =A0 int float_isnan =A0 =A0 =A0 (float x) =A0 =A0 =A0 { return isnan(x= ); } > =A0 =A0 int double_isnan =A0 =A0 =A0(double x) =A0 =A0 =A0{ return isnan(x= ); } > =A0 =A0 int long_double_isnan (long double x) { return isnan(x); } > > and then provide Ada interfaces to those C functions. > > It's a bit of a roundabout way to do it (providing three distinct > function wrappers for a single macro that's probably a wrapper for > three distinct underlying functions), but it should work. > > -- > Keith Thompson (The_Other_Keith) > Nokia > "We must do something. =A0This is something. =A0Therefore, we must do this= ." > =A0 =A0 -- Antony Jay and Jonathan Lynn, "Yes Minister" That looks doable. As an aside, I remember the early Pascal compilers on Macintosh (Apple's own and the much-missed THINK Pascal nee MacPascal) dealt with all of the 754 spec (as far as I know, which isn't very far) and was very well documented in a book called Apple Numerics Manual with unspecified authorship but with a forward by Prof. Kahan of UC Berkeley. MacPascal did 96-bit floating point when it ran without hardware acceleration and fell back to 80 bits with a FPU. Jerry