comp.lang.ada
 help / color / mirror / Atom feed
From: Bob Duff <bobduff@theworld.com>
Subject: Re: Fixed-point question
Date: Sat, 27 Jun 2015 16:42:07 -0400
Date: 2015-06-27T16:42:07-04:00	[thread overview]
Message-ID: <876168sx28.fsf@theworld.com> (raw)
In-Reply-To: mmmv4f$fr8$1@dont-email.me

"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:

> Root_Real, right. I still tend to think in terms of the rules for Ada 83.

;-)

> So for C1, the compiler is looking for a visible "/" that yields a result that
> can be converted to Fixed_Type.

Close.  It's looking for a "/" that has two parameters that can be
converted from universal_real -- the two literals.  Or were they named
numbers (I forget)?  The result of those "/" ops can be anything,
because type conversions don't provide an expected type (i.e. the
expected type for the operand of a type conversion is "any type").

>...These include those for at least Root_Real,
> Float, Duration, and Fixed_Type. 8.6(29) results in Root_Real's "/" being selected.

Right.

> For C2, the compiler is looking for a visible "/" that yields a result of
> Fixed_Type, and only Fixed_Type's "/" does that.

Well, fixed-point division is kind of magical.  The individual
fixed-point types don't have a "/" that takes parameters of the type and
returns the same type, but there's a "/" on universal_fixed that can be
used on any fixed-point types, and the two operands and result can all
be of different fixed-point types.  See 4.5.5(18).  Similar for "*".
There are also mixed fixed-integer ops for each fixed-point type.

There's a rule somewhere that says the context has to provide
the type of the result, so the compiler knows how much precision
is needed.  E.g. you can say "X := Y * Z;" but not
"X := Y * Z * W;".

> Is that anything close to correct?

Yes, close enough to understand what the program does at run time,
although not quite close enough to write a correct Ada compiler.  ;-)

- Bob


  reply	other threads:[~2015-06-27 20:42 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-26 13:20 Fixed-point question Patrick Noffke
2015-06-26 16:56 ` Jeffrey R. Carter
2015-06-26 18:21   ` Patrick Noffke
2015-06-26 20:21     ` Anh Vo
2015-06-26 20:25     ` Jeffrey R. Carter
2015-06-27  2:55       ` Patrick Noffke
2015-06-26 23:14     ` Qun-Ying
2015-06-27  3:00       ` Patrick Noffke
2015-06-27  4:44         ` Jeffrey R. Carter
2015-06-27 17:59           ` Patrick Noffke
2015-06-27 18:38             ` Jeffrey R. Carter
2015-06-27 19:20               ` Bob Duff
2015-06-27 19:57                 ` Jeffrey R. Carter
2015-06-27 20:42                   ` Bob Duff [this message]
2015-06-28 11:39                     ` Brian Drummond
2015-06-29 13:28                     ` Patrick Noffke
2015-06-29 14:13                       ` Bob Duff
2015-06-27 23:41               ` Anh Vo
  -- strict thread matches above, loose matches on Subject: below --
1995-04-01  0:00 Garlington KE
1995-04-06  0:00 ` Robert Dewar
1995-04-07  0:00   ` Robert I. Eachus
1995-04-07  0:00     ` Robert Dewar
1995-04-07  0:00   ` Garlington KE
1995-04-07  0:00     ` 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