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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,184737148aef02ac X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Fixed point multiplication ambiguity Date: 1999/01/28 Message-ID: #1/1 X-Deja-AN: 437799223 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <78od6d$b4t$2@plug.news.pipex.net> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1999-01-28T00:00:00+00:00 List-Id: Nick Roberts (Nick.Roberts@dial.pipex.com) wrote: : Tucker Taft wrote in message ... : [...] : |: procedure Tf is : | : |: D : Duration := 5.0; : | : |: Dec_Delt : Integer := Integer (D * 10.0 + 0.5); : | : |This is legal. Overload resolution interprets "D * 10.0" as returning : |universal_fixed. This is implicitly convertible to Duration (as well : |as any other fixed point type), as is 0.5. Presuming there is no : |other fixed-point type with a directly visible "+", this should resolve, : |and use the "+" of Duration. : [...] : Yes, this is legal, but Tucker's explanation is not precisely right. I believe I am right (see below). : ... The D*10.0 does resolve as Tucker says, giving a universal_fixed. The 0.5 : literal is a universal_real. Thus adding them gives us the pattern : "+"(universal_fixed,universal_real) return unknown. However, it is the rule : in RM 8.6 [29,30] preferring root types that allows this to be resolved into : the pattern "+"(root_real,root_real) return root_real implied by RM 4.5.3 : [2]. So the expression D*10.0+0.5 returns a value of type root_real, which : can then be converted to an integer and assigned to Dec_Delt. Sorry, but you are wrong. Universal_fixed is *not* implicitly convertible to root_real. It is implicitly convertible to any *fixed point* type, and to universal_real (because any real type is implicitly convertible both *to* and *from* universal real), but *not* to root_real (I realize only a died-in-the-wool language lawyer will believe this reasoning). : However, the expression Integer(D*10.0+0.5) causes a root_real addition and : conversion to integer to be executed dynamically. No, this expression uses Duration's "+", because this is effectively equivalent to: Integer(Duration(D*10.0)+Duration(0.5)) The whole fixed-point multiplication model is pretty obscure, unfortunately. : ... : ------------------------------------------- : Nick Roberts : ------------------------------------------- -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA