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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,64012d256cd76a8d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-08 23:47:11 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!snoopy.risq.qc.ca!newsfeed.news2me.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail From: "Eric G. Miller" Subject: Re: Gnat/Windows float point Q User-Agent: Pan/0.13.4 (She had eyes like strange sins. (Debian GNU/Linux)) Message-ID: Newsgroups: comp.lang.ada References: <1MGka.57623$ug3.113346@rwcrnsc51.ops.asp.att.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Date: Wed, 09 Apr 2003 06:47:11 GMT NNTP-Posting-Host: 216.119.12.84 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 1049870831 216.119.12.84 (Tue, 08 Apr 2003 23:47:11 PDT) NNTP-Posting-Date: Tue, 08 Apr 2003 23:47:11 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:36004 Date: 2003-04-09T06:47:11+00:00 List-Id: In <1MGka.57623$ug3.113346@rwcrnsc51.ops.asp.att.net>, tmora wrote: > What does it mean when float'image(x) = " 47.720649 0.E+05" ? > ??? > > Is x a NAN or something? It causes a Constraint_Error in > the "return x" statement in: > > subtype units is float range 0.0 .. 1.0; > function clip(x: float) return units is > begin > if x < 0.0 then return 0.0; > elsif x > 1.0 then return 1.0; > else return x; > end if; > end clip; Check X'Valid if the data comes from some route like Unchecked_Conversion. The following demonstrates the conversion error on some systems.. with Ada.Text_Io; use Ada.Text_Io; with Ada.Unchecked_Conversion; procedure Unitarians is subtype Units is Float range 0.0 .. 1.0; function Clip(X: Float) return Units is begin if X'Valid = False then raise Constraint_Error; end if; if X < 0.0 then return 0.0; elsif X > 1.0 then return 1.0; else return X; end if; end Clip; type Byte4 is mod 2**32; function To_Float is new Ada.Unchecked_Conversion (Byte4, Float); U : Units; F : Float; UI : Byte4 := 16#FFFF_FFFF#; begin Put_Line ("UI = " & Byte4'Image (UI)); F := To_Float (UI); Put_Line ("F is valid? --> " & Boolean'Image(F'Valid)); U := Clip (F); Put_Line ("U = " & Units'Image(U)); end Unitarians; -- echo ">gra.fcw@2ztr< eryyvZ .T pveR" | rot13 | reverse