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

* Re: Ada decimal elaboration, further experimentation.
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Dik T. Winter @ 1988-07-03 23:36 UTC (permalink / raw)


In article <8807031845.AA01533@ajpo.sei.cmu.edu> CONTR47@NOSC-TECR.ARPA writes:
 > Norm Cohen writes:
...
 > 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.
 > ------------------------------
 > 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
...
 > How about other people trying this in case I'm
 > missing something and also to see how other

Yes, you are.  Norm did *not* mean constant dollar_type, but just constant.
You still are trying to get an implicit conversion from a universal real
expression to something of type dollar_type.  This is not possible, as noted
by Norm.

Oh, BTW, our system (DG) gives:
My dime is .102
Your dime is .078
which is wrong on two counts.
-- 
dik t. winter, cwi, amsterdam, nederland
INTERNET   : dik@cwi.nl
BITNET/EARN: dik@mcvax

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

* Re: Ada decimal elaboration, further experimentation.
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Murphy @ 1988-07-05 23:39 UTC (permalink / raw)


The more serious problem here which is what *really* causes the bad
numbers is that most (all?) Ada compilers only support fixed point numbers
that are a power of two.  So despite the type declaration with a
delta of 0.01, the actual delta used is 0.0078125 (2e-7).  This makes
decimal arithmetic using fixed point unworkable.

-- Michael Murphy

P.S.  The VADS 5.5 compiler for the ELXSI prints out 0.10 for all
my_dime calculations (constant or not) because they are all done with 
universal arithmetic, but your_dime is 0.08 for the above reason.

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

* Re: Ada decimal elaboration, furthe
  1988-07-05 23:39   ` Michael Murphy
@ 1988-07-09 19:22     ` stt
  0 siblings, 0 replies; 4+ messages in thread
From: stt @ 1988-07-09 19:22 UTC (permalink / raw)



I would expect that things will improve as ACVC 1.10 takes hold,
where Chapter 13 is no longer seen as "optional" by
compiler writers...
-Tucker Taft
Intermetrics, Inc.
Cambridge, MA  02138

^ 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