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 12:29:25 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: <1993Jul21.082925.3193@sei.cmu.edu> List-Id: mfeldman@seas.gwu.edu (Michael Feldman) asked about why his compiler stated that Constraint_Error would be raised by this statement: 27 TimeThen := TimeNow + 10 * Duration'(86400.0); In an earlier message I explained, and I then proposed another way to accomplish his goal of adding (in effect) days to a value of type Calendar.Time. Here's another approach to the latter problem. Declare a function like this: function "+"(Left: in Calendar.Time; Days: in integer) return Calendar.Time; In the body, call Calendar.Split on Left, and add Days to the DAY result. While the result exceeds 365 (or 366 in leap years), subtract 365 (or 366) and add one to the year. This needs some care; details are left as an exercise for the student (or, in this case, the professor). Then put it all back together with Calendar.Time_Of. 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. If you put this function in a package My_Calendar, it can re-export the needed parts of package Calendar, so your application would mention only My_Calendar in a 'with' clause. Cheers! Art Evans ---------------------------------------------- Arthur Evans, Jr, PhD Ada Consultant 461 Fairview Road Pittsburgh PA 15238-1933 412-963-0839 ae@sei.cmu.edu