comp.lang.ada
 help / color / mirror / Atom feed
From: magnesium.club.cc.cmu.edu!news.sei.cmu.edu!ae@uunet.uu.net  (Arthur Evans
Subject: Re: Can you help with fixed-point arithmetic?
Date: 21 Jul 93 02:03:09 GMT	[thread overview]
Message-ID: <1993Jul20.220309.1563@sei.cmu.edu> (raw)

mfeldman@seas.gwu.edu (Michael Feldman) asks (in effect) why his
compiler reports that Constraint_Error will be raised from the statement
       27    TimeThen := TimeNow + 10 * Duration'(86400.0);

Consider in isolation
	10 * Duration'(86400.0)
This is a multiplication whose left operand is an integer and whose
right operand is of type Duration, and we find its semantics in
4.5.5(7), where we learn that its result type will be of type Duration.

The probable problem is that the result is too big for that type.
Although the LRM doesn't specify Duration's range (see C(19)), the usual
value is not much more than enough to store 24 hours.  (A larger range
is counter-productive, as it decreases the fineness.)  The range for
Duration in Meridian Ada on the Mac is
	-86400.0 .. 86400
I suspect it's the same on the PC.

Next question: how to get around the problem.  A way that at first seems
plausible is to declare a fixed-point type with a large enough range and
convert 86400.0 to that.  This won't work, though, since the '+' on line
27 wouldn't be defined.  (It's now the '+' exported by package
Calendar.)

If I were doing this and cared about dates only and not time, I would
ignore package Calendar and just represent dates as an integer offset
from some origin.  If you care about time, declare a record with such an
integer and a Duration field for time.  I'm sure you can think of other
ideas.

Cheers!

Art Evans
----------------------------------------------
Arthur Evans, Jr, PhD           Ada Consultant
461 Fairview Road
Pittsburgh PA  15238-1933
412-963-0839
ae@sei.cmu.edu

             reply	other threads:[~1993-07-21  2:03 UTC|newest]

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

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