comp.lang.ada
 help / color / mirror / Atom feed
From: sommar@enea.se (Erland Sommarskog)
Subject: Re: Ada and Decimal Arithmetic
Date: 6 Jul 88 19:12:01 GMT	[thread overview]
Message-ID: <3663@enea.se> (raw)

Marc.Graham@SEI.CMU.EDU writes:
>I was fascinated to note that in neither Ed Berard's post on Ada and
>commercial usage, nor in any of its responses, was the issue of Ada
>and decimal arithmetic mentioned. I would have thought that Ada's lack
>of support for decimal arithmetic is a major impediment to the use of
>Ada in commercial applications. Indeed, if I were asked to render a
>professional judgement on Ada to a commercial client, lack of decimal
>support would in itself be enough to reject it.

While it is true that Ada does not contain itself decimal arithmetic
accurate to the last bit, it is easy to implement. Basically:

Package Decimal_arithmetic is
    Type Fixed_point(No_of_dec : Natural) is private; -- Possibly limited 
    -- Operations on Fixed_point, arithmetics and I/O.
Private
    Type Fixed_point(No_of_dec : Natural) is   -- for instance 
    Record
       Int_part   : integer;
       Fractional : integer;
    End record;
End package;

What you miss is that you can't have fixed point literals. 1.02 may
not reliable. But this easy solved with a Set_fixed_point operation 
that takes two integer parameters.

Someone pointed out that to count your money, you may as well count
in cents. This is perfectly true. However, the problem arises when
you have things like interest rates. I'm working with a commercial
application for the moment. We use VAX-Pascal, so we don't have the
same possibilities for abstract data types as in Ada. And when you
are dealing with a percent figure, you must know whether it's 0, 2
or 4 decimals for this one. If two people interpret it differently,
an error will be introduced. 

Being in the line of scaled integers: If one believe that this is
a problem which occurs only in commercial applications, one is wrong.
My project before this one was a graphical package to be used in radar 
systems. We used scaled integers. Due to real-time requirements we had 
no time for floating point calcualations.
-- 
Erland Sommarskog           
ENEA Data, Stockholm        
sommar@enea.UUCP            
"It all looks quite impressive really, but is it really necessary?" Radio Stars

             reply	other threads:[~1988-07-06 19:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1988-07-06 19:12 Erland Sommarskog [this message]
  -- strict thread matches above, loose matches on Subject: below --
1988-06-29 13:03 Ada and decimal arithmetic CONTR47
1988-06-29 15:11 ` Vincent P. Broman
1988-06-30 21:03   ` smryan
1988-06-28 21:57 Ada and Decimal Arithmetic Marc.Graham
replies disabled

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