From: seas.gwu.edu!mfeldman@uunet.uu.net (Michael Feldman)
Subject: Re: Can you help with fixed-point arithmetic?
Date: 21 Jul 93 22:19:48 GMT [thread overview]
Message-ID: <1993Jul21.221948.25724@seas.gwu.edu> (raw)
In article <1993Jul20.220309.1563@sei.cmu.edu> ae@sei.cmu.edu (Arthur Evans) wr
ites:
>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.)
>
Yep, I got stung by forgetting that the LRM does not require a Duration
range of more than a day. In any event, thanks to all of you who pointed
this out by e-mail and on the net. I'll find another way.
Actually, I'd decided to represent a date as a record containing year
and Julian date within year (1..365 or 1..366) but thought I could get
away with simpler date arithmetic by using built-in operations> I guess
my original design was OK after all.
Thanks!
Mike Feldman
------------------------------------------------------------------------
Michael B. Feldman - co-chair, SIGAda Education Committee
Professor, Dept. of Electrical Engineering and Computer Science
The George Washington University - Washington, DC 20052 USA
202-994-5253 (voice) - 202-994-0227 (fax) - mfeldman@seas.gwu.edu (Internet)
"We just changed our CONFIG.SYS, then pressed CTRL-ALT-DEL. It was easy."
-- Alexandre Giglavyi, director Lyceum of Information Technologies, Moscow.
------------------------------------------------------------------------
next reply other threads:[~1993-07-21 22:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1993-07-21 22:19 Michael Feldman [this message]
-- strict thread matches above, loose matches on Subject: below --
1993-07-21 18:13 Can you help with fixed-point arithmetic? Mark A Biggar
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