comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org>
Subject: Re: conversions between fixed-point types
Date: Mon, 21 Sep 2009 10:24:09 -0700
Date: 2009-09-21T10:24:09-07:00	[thread overview]
Message-ID: <h98cb3$1vo$1@news.tornevall.net> (raw)
In-Reply-To: <h94obl$c7h$1@news.albasani.net>

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



  parent reply	other threads:[~2009-09-21 17:24 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-18 21:35 conversions between fixed-point types Dirk Herrmann
2009-09-18 22:42 ` Adam Beneschan
2009-09-19 12:41 ` Dirk Herrmann
2009-09-19 14:48   ` John B. Matthews
2009-09-20  8:15     ` Dirk Herrmann
2009-09-20 14:22       ` Robert A Duff
2009-09-20 18:55         ` Dirk Herrmann
2009-09-20 20:34           ` Simon Clubley
2009-09-23 20:46             ` Dirk Herrmann
2009-09-27 17:15               ` Simon Clubley
2009-09-27 19:22           ` sjw
2009-09-28 20:18             ` Dirk Herrmann
2009-09-28 18:37           ` Robert A Duff
2009-09-28 20:50             ` Dirk Herrmann
2009-09-20 15:18       ` John B. Matthews
2009-09-20 19:13         ` Dirk Herrmann
2009-09-20 20:09       ` tmoran
2009-09-21 17:24       ` Jeffrey R. Carter [this message]
2009-09-23 20:57         ` Dirk Herrmann
2009-09-23 22:28           ` Jeffrey R. Carter
2009-09-24  1:05             ` Adam Beneschan
2009-09-24  3:57               ` Jeffrey R. Carter
2009-09-25  8:47               ` Stuart
2009-09-25 20:41                 ` sjw
2009-09-25 21:58                   ` Jeffrey R. Carter
2009-09-28 13:40                   ` Stuart
2009-09-26 14:43                 ` Dirk Herrmann
2009-09-28 15:15                   ` Adam Beneschan
2009-09-26 14:31               ` Dirk Herrmann
2009-09-19 18:38   ` tmoran
2009-09-20  8:22 ` sjw
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox