comp.lang.ada
 help / color / mirror / Atom feed
From: CONTR47@NOSC-TECR.ARPA
Subject: Ada decimal elaboration, further experimentation.
Date: 3 Jul 88 18:49:22 GMT	[thread overview]
Message-ID: <8807031845.AA01533@ajpo.sei.cmu.edu> (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
-------------------

             reply	other threads:[~1988-07-03 18:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1988-07-03 18:49 CONTR47 [this message]
1988-07-03 23:36 ` Ada decimal elaboration, further experimentation Dik T. Winter
1988-07-05 23:39   ` Michael Murphy
1988-07-09 19:22     ` Ada decimal elaboration, furthe stt
replies disabled

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