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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,23a8a20ef7e9405e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!eternal-september.org!.POSTED!not-for-mail From: Warren Newsgroups: comp.lang.ada Subject: Re: S'Is_nan or S'Is_inf? Date: Fri, 16 Jul 2010 22:35:14 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <1tbp3geoa5yna$.171cmlfdrbm98$.dlg@40tude.net> Injection-Date: Fri, 16 Jul 2010 22:35:14 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="lBs9bB9W+DZ7mhZRWeZ0DQ"; logging-data="17481"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ksgAE9J8dcHwXGS85Sd1wiMnPVAL1oAM=" User-Agent: Xnews/5.04.25 X-Face: &6@]C2>ZS=NM|HE-^zWuryN#Z/2_.s9E|G&~DRi|sav9{E}XQJb*\_>=a5"q]\%A;5}LKP][1mA{gZ,Q!j Cancel-Lock: sha1:ftQ4jBSk3VfkRsxlEk0GAtNn4hA= Xref: g2news1.google.com comp.lang.ada:12447 Date: 2010-07-16T22:35:14+00:00 List-Id: Dmitry A. Kazakov expounded in news:1tbp3geoa5yna$.171cmlfdrbm98$.dlg@40tude.net: > with Ada.Text_IO; use Ada.Text_IO; > procedure IEEE is -- Only if Float is IEEE! > Zero : Float := 0.0; > Inf : Float := 1.0 / Zero; > NaN : Float := 0.0 / Zero; > begin > Put_Line ("Valid " & Boolean'Image (Inf'Valid)); > Put_Line ("In range " & Boolean'Image (Inf <= Float'Last)); > Put_Line ("Self NaN " & Boolean'Image (NaN = NaN)); > end IEEE; > > On an IEEE machine it could print 3x FALSE. To detect NaN then, this seems to work: function Is_Nan(F : Float) return Boolean is begin if not F'Valid then return not ( Is_Infinity(F) or Is_Neg_Infinity(F) ); else return False; end if; end Is_Nan; where Is_Infinity(F) etc. is implemented as suggested. Essentially if not valid, but not one of the infinities(+ or -), then it must be NaN. This works with Gnat on Cygwin. I'll need to test it on other platforms, but hopefully most if not all IEEE platforms will support this. Warren