From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 21 Jul 93 22:19:48 GMT From: seas.gwu.edu!mfeldman@uunet.uu.net (Michael Feldman) Subject: Re: Can you help with fixed-point arithmetic? Message-ID: <1993Jul21.221948.25724@seas.gwu.edu> List-Id: 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. ------------------------------------------------------------------------