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=-0.9 required=3.0 tests=BAYES_00,FROM_ADDR_WS autolearn=no autolearn_force=no version=3.4.5-pre1 Date: 21 Jul 93 02:03:09 GMT 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? Message-ID: <1993Jul20.220309.1563@sei.cmu.edu> List-Id: 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