From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ac48cedaf5c5cba3 X-Google-Attributes: gid103376,public From: ncohen@watson.ibm.com (Norman H. Cohen) Subject: Re: Integer truncation and other recipes Date: 1996/06/05 Message-ID: <4p4atg$tc5@watnews1.watson.ibm.com>#1/1 X-Deja-AN: 158615578 distribution: world references: <4nv3tmINNql5@oasys.dt.navy.mil> organization: IBM T.J. Watson Research Center reply-to: ncohen@watson.ibm.com newsgroups: comp.lang.ada Date: 1996-06-05T00:00:00+00:00 List-Id: In article , jsa@organon.com (Jon S Anthony) writes: |> In article je@bton.ac.uk (John English) writes: |> |> > : > In Ada, how do you convert from a real to an integer by truncation? |> > : > That is, how would you convert a value such as 1.9 to 1? |> > : Go to index and find entry: |> > : Truncation attribute |> > |> > Fine for floating point types, but you're out of luck if you want to truncate |> > *fixed point* types, for which the 'Truncation attribute isn't available... |> |> First convert to floating point... Not a very satisfying answer. Suppose you want to delay until the next time the minute hand sweeps past the 12. It would be nice to be able to write: declare Now : Duration := Ada.Calendar.Seconds(Ada.Calendar.Clock); This_Minute : Duration := Duration'Floor(Now/60.0) * 60.0; -- ILLEGAL!!! There is not really a Duration'Floor -- attribute! Next_Minute : Duration := This_Minute + 60.0; begin delay until Next_Minute; end; Duration(Float'Floor(Float(Now)/60.0)) is a poor substitute for Duration'Floor(Now/60.0). I think the failure to generalize certain of the floating-point attributes to fixed-point types was an unfortunate oversight. -- Norman H. Cohen ncohen@watson.ibm.com