comp.lang.ada
 help / color / mirror / Atom feed
From: NCOHEN@IBM.COM (Norman Cohen)
Subject: Ada decimal math, an example (or counterexample)
Date: 1 Jul 88 17:54:52 GMT	[thread overview]
Message-ID: <070188.135453.ncohen@ibm.com> (raw)

Sam Harbaugh expects the addition in

  my_dime : dollar_type :=
  0.01 + 0.01 + 0.01 + 0.01 + 0.01 + 0.01 + 0.01 + 0.01 + 0.01 + 0.01;
--   1      2      3      4      5      6      7      8      9     10

to be performed using universal_real addition rather than dollar_type
addition.  Actually, it is performed using dollar_type addition:  Each
real literal is implicitly converted to dollar_type and the ten resulting
dollar_type values are summed.

If Sam had written

  my_dime : constant :=
    0.01 + 0.01 + 0.01 + 0.01 + 0.01 + 0.01 + 0.01 + 0.01 + 0.01 + 0.01;

then exact universal_real addition would have been performed.

The Ada rule is that conversion takes place only at the bottom of the
expression tree: Only numeric literals, named numbers, and attributes
with universal results are convertible.

The rule is given in RM paragraph 4.6(15).  Paragraph 4.6(20) provides
enlightening examples.

Norman Cohen
IBM Research

             reply	other threads:[~1988-07-01 17:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1988-07-01 17:54 Norman Cohen [this message]
  -- strict thread matches above, loose matches on Subject: below --
1988-07-06 18:48 Ada decimal math, an example (or counterexample) Gary Morris @flash
1988-06-30 21:53 CONTR47
replies disabled

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