From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: Integer truncation and other recipes
Date: 1996/06/05
Date: 1996-06-05T00:00:00+00:00 [thread overview]
Message-ID: <4p4atg$tc5@watnews1.watson.ibm.com> (raw)
In-Reply-To: JSA.96Jun4154923@organon.com
In article <JSA.96Jun4154923@organon.com>, jsa@organon.com (Jon S Anthony)
writes:
|> In article <DsGC9A.4KD@bton.ac.uk> 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
next prev parent reply other threads:[~1996-06-05 0:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-05-22 0:00 Integer truncation and other recipes Paul Shedlarski
1996-05-23 0:00 ` Jon S Anthony
1996-06-04 0:00 ` John English
1996-06-04 0:00 ` Jon S Anthony
1996-06-05 0:00 ` Norman H. Cohen [this message]
1996-06-05 0:00 ` Robert I. Eachus
1996-06-08 0:00 ` Jon S Anthony
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox