comp.lang.ada
 help / color / mirror / Atom feed
From: stt@henning.camb.inmet.com (Tucker Taft)
Subject: Re: Float to Fixed conversions
Date: Sat, 18 Mar 1995 13:01:42 GMT
Date: 1995-03-18T13:01:42+00:00	[thread overview]
Message-ID: <D5n06v.D8F@inmet.camb.inmet.com> (raw)
In-Reply-To: D5K14n.C97@lazrus.cca.rockwell.com

Wayne Magor (wemagor@fmsa.cca.rockwell.com) wrote:

: Is it legal for the program below to print 0.0?  The reason I question it
: is because it is DEC's Vax Ada that returns 0.0, but their Alpha Ada
: returns 1.0.  The 'Machine_Rounds is FALSE for Vax and TRUE for Alpha,
: but a compiler on a Sun machine has 'Machine_Rounds to be FALSE and yet
: still returns 1.0.

Conversions between (ordinary) fixed and float can either truncate or round.
The 'Machine_Rounds attribute of the *target* type "should" tell you
which one happens, but that attribute is mostly oriented toward operations
within a type, not conversions between types.  Have you checked
the 'Machine_Rounds attribute of type Fix?

(By the way, in Ada 95, conversion to *decimal* fixed point requires 
truncation, unless you use the 'Round attribute function.)

: Is there a way to adjust for these differences or is there just a bug in
: the Vax Ada compiler?  Is the conversion different if it is exactly half
: way between the fixed point model numbers?

Being exactly half way is not a special case for conversions to real type.
On the other hand, when converting from real to integer, rounding is required
and in Ada 95, if exactly halfway between two integers, the result has
to be rounded away from zero (Ada 83 allows either direction in this case).

See RM95 4.6(29-33) for the official rules, plus G.2.3(24).

: procedure Fixed_Pt is
:   type Fixed is delta 1.0 range -10.0 .. 10.0;
:   Fix : Fixed;
:   Flt : Float := 0.999;
: begin
:   Fix := Fixed(Flt);  -- should Fix alway be set to 1.0?
: end Fixed_Pt;

-Tucker Taft  stt@inmet.com
Intermetrics, Inc.



  reply	other threads:[~1995-03-18 13:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-03-16 22:29 Float to Fixed conversions Wayne Magor
1995-03-18 13:01 ` Tucker Taft [this message]
1995-03-20 21:29   ` Wayne Magor
1995-03-19  1:31 ` Robert Dewar
replies disabled

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