comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@mitre-bedford.arpa  (Robert I. Eachus)
Subject: Re: Can you help with fixed-point arithmetic?
Date: 21 Jul 93 16:38:58 GMT	[thread overview]
Message-ID: <EACHUS.93Jul21113858@spectre.mitre.org> (raw)

    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...

             reply	other threads:[~1993-07-21 16:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-07-21 16:38 Robert I. Eachus [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-07-21 22:19 Can you help with fixed-point arithmetic? Michael Feldman
1993-07-21 18:13 Mark A Biggar
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