comp.lang.ada
 help / color / mirror / Atom feed
From: dst17!mab@ford-wdl1.arpa  (Mark A Biggar)
Subject: Re: Can you help with fixed-point arithmetic?
Date: 21 Jul 93 18:13:57 GMT	[thread overview]
Message-ID: <1993Jul21.181357.12063@wdl.loral.com> (raw)

In article <1993Jul21.082925.3193@sei.cmu.edu> ae@sei.cmu.edu (Arthur Evans) wr
ites:
>If you want to add both days and partial days, give this "+" a third
>parameter of type Duration.  Again, detect the possible overflow and
>propagate a carry into DAY.  Be careful -- there are subtleties in
>detecting the overflow.  Consider
>	if SECONDS + Increment > 86400.0 then
>Your compiler is not incorrect if it lets Constraint_Error be raised in
>evaluating the sum.  It's also not incorrect if it does the comparison
>correctly, dealing with an intermediate result (the sum) outside the
>range of type Duration.  In the worst case you may have to just do the
>sum and detect the Constraint_Error.

Sense, Increment is of type Duration (and probably positive as well) why
not just code the above condition as:

	if SECONDS > 86400.0 - Increment then

which correct detects the overflow and never raises Constraint_Error.
If Increment can be negitive, then you have to split the code into two cases
to handle the Carry vs Barrow cases after the call the Split anyway, so you
might as well use two different overflow tests.

It is almost alway possible to write an overflow test for addition in such
a way as to never raise Constraint_Error.  Dectecting overflow of multiplcation
is much more difficult.

--
Mark Biggar
mab@wdl.lroal.com

             reply	other threads:[~1993-07-21 18:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-07-21 18:13 Mark A Biggar [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-07-21 22:19 Can you help with fixed-point arithmetic? Michael Feldman
1993-07-21 16:38 Robert I. Eachus
1993-07-21 12:29 magnesium.club.cc.cmu.edu!news.sei.cmu.edu!ae
1993-07-21  2:03 magnesium.club.cc.cmu.edu!news.sei.cmu.edu!ae
replies disabled

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