comp.lang.ada
 help / color / mirror / Atom feed
* Ada decimal elaboration, further experimentation.
@ 1988-07-03 18:49 CONTR47
  1988-07-03 23:36 ` Dik T. Winter
  0 siblings, 1 reply; 4+ messages in thread
From: CONTR47 @ 1988-07-03 18:49 UTC (permalink / raw)


Norm Cohen writes:
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

------------------------------
Wellll. I tried Norm's suggestion (assuming he meant
"constant dollar_type" instead of just "constant") so that
my_dime : constant dollar_type := 0.01 + 0.01 etc. for a total of ten 0.01s
Janus said my_dime is worth 0.08
Alsys said my_dime is worth 0.10
Dec said my_dime is worth  0.08
How about other people trying this in case I'm
missing something and also to see how other
compilers handle this.
regards,sam harbaugh
-------------------

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1988-07-09 19:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1988-07-03 18:49 Ada decimal elaboration, further experimentation CONTR47
1988-07-03 23:36 ` Dik T. Winter
1988-07-05 23:39   ` Michael Murphy
1988-07-09 19:22     ` Ada decimal elaboration, furthe stt

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