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: a07f3367d7,6fabd104d18f3943 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!usenet-fr.net!club-internet.fr!feedme-small.clubint.net!news.tornevall.net!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: conversions between fixed-point types Date: Mon, 21 Sep 2009 10:24:09 -0700 Organization: TornevallNET - http://news.tornevall.net Message-ID: References: NNTP-Posting-Host: d1f5029d760148ef6b9bdbcde3a174fa Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: eda1f9015e69141da9eb2ec12d9a0dc9 X-Complaints-To: abuse@tornevall.net X-Complaints-Language: Spoken language is english or swedish - NOT ITALIAN, FRENCH, GERMAN OR ANY OTHER LANGUAGE! In-Reply-To: X-Validate-Post: http://news.tornevall.net/validate.php?trace=eda1f9015e69141da9eb2ec12d9a0dc9 X-SpeedUI: 1738 X-Complaints-Italiano: Parlo la lingua non � italiano User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) X-Posting-User: 9b22bfe2855937f9b3faeec7cfc91295 Xref: g2news2.google.com comp.lang.ada:8417 Date: 2009-09-21T10:24:09-07:00 List-Id: Dirk Herrmann wrote: > > In particular I am disturbed by the fact that the following two lines > produce different results with GNAT, as has been confirmed for GNAT > 3.15p (thanks, tmoran): > FIO.Put(Float(FpB(Float(-1.5)))); TIO.Put(" "); --> -1.20000E+00 > FIO.Put(Float(MakeB(-1.5))); TIO.Put(" "); --> -1.60000E+00 > In the first line, the conversion to FpB is done from a Float value, > which is a direct cast from -1.5. In the second line, the conversion to > FpB is also done from a Float value, but in this case -1.5 is passed as > a Float argument to MakeB. What I don't understand is, why it should > make a difference whether I cast -1.5 to Float and then convert it to > FpB compared to the situation where -1.5 is converted to a Float > argument, which is then converted to FpB. You are complicating matters with your functions and your conversions to and from Float. Since IIRC your target H/W doesn't support floating-point, you will be able to see what happens and formulate your questions better if you deal only with the fixed-point types and direct type conversions between them: A : Fpa := -1.5; B : Fpb := Fpb (A); ... Ada.Text_IO.Put_Line (Fpb'Image (B) ); What you have called a "direct cast" is a type conversion. Also, it is never necessary to convert a real numeric literal to a real type. Your 1st line could be written as FIO.Put (Float (Fpb (Float'(-1.5) ) ) ); With the apostrophe, this is a "qualified expression" and tells the compiler that the expression in the parentheses is of type Float. However, I suspect that FIO.Put (Float (Fpb'(-1.5) ) ); is even better. -- Jeff Carter "It's all right, Taggart. Just a man and a horse being hung out there." Blazing Saddles 34