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,c6f0d0c4aaf03392 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!e3g2000cwe.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Universal float or not - who's right ? Date: 8 Sep 2006 10:13:37 -0700 Organization: http://groups.google.com Message-ID: <1157735617.791199.13280@e3g2000cwe.googlegroups.com> References: <45016cb7$1_4@news.bluewin.ch> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1157735622 10514 127.0.0.1 (8 Sep 2006 17:13:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 8 Sep 2006 17:13:42 +0000 (UTC) User-Agent: G2/0.2 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) Complaints-To: groups-abuse@google.com Injection-Info: e3g2000cwe.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:6524 Date: 2006-09-08T10:13:37-07:00 List-Id: Gautier wrote: > Hullo - here is a nice case, with a trivial workaround given first, where 3 > compiler differs. Question to the Ada RM exegetes: who is right ? > > package FF is > type FFloat is new Float; > end; > with FF; > > procedure Beauripple is > > generic > type Num is digits <>; > x : Num; > package P is end; > > c: constant:= 2.0**4; > package FPc is new P(FF.FFLoat,c); > -- Passes on compilers A,B,C - as expected > > d: constant FF.FFLoat:= 2.0**4; > -- Fails on compiler A,B,C > -- "**" is not visible, an "use FF;" is missing > > package FPe is new P(FF.FFLoat,2.0**4); > -- ** A,B,C differ: > -- Passes on C: (2.0**4) probably taken as universal float > -- Fails on compiler A,B: same reason as for constant d > > begin > null; > end; The declaration of "d" and of the instance FPe should both be rejected, but understanding why requires understanding the difference between universal_real and root_real, which is something that always confuses the daylights out of me, so I hope I'm getting this right. All floating-point literals are universal_real and can be used as an actual for any subprogram parameter that is of any real type. However, universal_reals don't have primitive subprograms, so there's no "**" that returns a universal_real. Instead, there's a "**" that takes a root_real and an Integer'Base parameter and returns a root_real. When you say 2.0**4, and the "**" implicitly defined for FFloat is not visible, then "**" can refer to the subprogram function "**" (Left : root_real; Right : Integer'Base) return root_real; or to a "**" function defined for a predefined type like Float. When you say d: constant FF.FFloat := 2.0**4; the expected type for the expression is FF.FFloat. This means that the expression can have type FF.FFloat or it can be a universal_real, but it can't be any other type, including root_real. So it's illegal. The exact same logic applies to the instantiation---the expected type for the generic actual parameter is Num, which is the same as FF.FFloat. (So compiler C is wrong to accept it.) Both of these will work, though: d: constant FF.FFloat := c; d: constant FF.FFloat := FF.FFloat (2.0**4); --type conversion, not qualified expression!! The first works because "c" is a named number and therefore has type universal_real; in the second case, 2.0**4 will have type root_real which can be converted to FF.FFloat. Similarly for the instantiation (you've already demonstrated that using the named number works). References: RM95 3.3.1(4), 3.3.2(3,5), 3.4.1(6-7), 4.5.6(9-10), 8.6(22,24,29), 12.4(4) Hope this helps. -- Adam