From: hirasuna@acm.org (Michael Hirasuna)
Subject: Re: floats to integers?
Date: Sat, 25 Feb 1995 09:21:59 -0500
Date: 1995-02-25T09:21:59-05:00 [thread overview]
Message-ID: <hirasuna-2502950921590001@hirasuna.clark.net> (raw)
In-Reply-To: 3ie7je$dd9@newsbf02.news.aol.com
In article <EACHUS.95Feb14104008@spectre.mitre.org>,
eachus@spectre.mitre.org (Robert I. Eachus) wrote:
> Hmmm... If you want to always return a valid answer when possible,
> you need to do:
>
> function Floor (X: in Float) return Integer is
> Temp: Integer;
> begin
> Temp := Integer(X);
> if Float(Temp) > X then return Temp - 1; else return Temp; end if;
> exception
> when others =>
> if X < Float(Integer'LAST) + 1.0 and X >= Float(Integer'LAST)
> then return Integer'LAST;
> else raise Constraint_Error;
> end if;
> end Floor;
I receive another solution from Angel Alvarez (aalvarez@goya.eunet.es)
if Float(Integer(X)) = X
then return Integer(X);
else return Integer(X-0.5);end if;
At first glance this seems a more brute force approach, but is does avoid
the problems of the possible numeric error that may arise from integer
substraction.
--
Michael Hirasuna | hirasuna@acm.org
next parent reply other threads:[~1995-02-25 14:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <3i2gbu$56r@sanson.dit.upm.es>
[not found] ` <3ie7je$dd9@newsbf02.news.aol.com>
1995-02-25 14:21 ` Michael Hirasuna [this message]
1995-02-10 19:48 floats to integers? Ghada
1995-02-10 23:54 ` Michael Hirasuna
1995-02-11 10:06 ` John Howard
1995-02-11 14:51 ` Michael Hirasuna
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox