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 16:38:58 GMT From: eachus@mitre-bedford.arpa (Robert I. Eachus) Subject: Re: Can you help with fixed-point arithmetic? Message-ID: List-Id: Art has explainded the reason for the CONSTRAINT_ERROR, now for the solution(s). The first is a pain, the second is non-portable, and probably indicates a feature which can be added at low cost to Ada 9X. What you want to do is add days to times: with CALENDAR; use CALENDAR; ... function "+"(T: Time; Days: Integer) return Time is Y: Year_Number; M: Month_Number; D: Day_Number; S: Duration; begin Split(T,Y,M,D,S); -- do the arithmetic... return Time_Of(Y,M,D,S); end "+"; -- the simpler solution is to peer into private parts. SunAda: with Calendar; ... function "+"(T: Calendar.Time; Days: Integer) return Calendar.Time is type my_time is record -- lifted from calendar julian_day: integer; -- Julian Day Number sec: duration; end record; function To_Mine is new UNCHECKED_CONVERSION(Time,My_Time); function To_Time is new UNCHECKED_CONVERSION(My_Time,Time); Input: To_Mine(T); begin Input.Julian_Day := Input.Julian_Day+Days; return To_Time(Input); end "+"; In Ada_9X, it will be possible to extend Calendar with user defined children, so the Unchecked conversions are unnecessary. However, this particular function might make sense as an addition to Calendar. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...