comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: Truncation of FLOAT values
Date: 1996/04/19
Date: 1996-04-19T00:00:00+00:00	[thread overview]
Message-ID: <dewar.829958772@schonberg> (raw)
In-Reply-To: 4l8a6h$274@newsbf02.news.aol.com

John Herro said

"function Floor(X : in Float) return Integer is
   Answer : Integer := Integer(X);
begin
   if Float(Answer) > X then
      Answer := Answer - 1;
   end if;
   return Answer;
end Floor;"

Although this will typically work, Ada semantics do not guarantee that
it will work.

X may not be a model number, suppose that in fact X is
1.99999999999999999999999999999999

representing a number that is less than the model number 2.0, but
greater than the largest model number less than 2.0. 

Now answer will surely be 2

Float(Answer) is the model number 2.0

but since x is not a model number, it can be treated as though it were
any number in its model interval, and in particular as 2.0, so that
the test may yield false and the final restul returned is 2 instead
of 1.

You can actually imagine this happening with some scenarios of extended
values being passed in registers.


Floating-point semantics are very delicate :-)





  reply	other threads:[~1996-04-19  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-18  0:00 Truncation of FLOAT values Franz Kruse
1996-04-18  0:00 ` Cordes MJ
1996-04-19  0:00   ` Peter Hermann
1996-04-19  0:00   ` John Herro
1996-04-19  0:00     ` Robert Dewar [this message]
1996-04-22  0:00       ` John Herro
1996-04-22  0:00     ` Robert I. Eachus
1996-04-19  0:00   ` Robert Dewar
1996-04-20  0:00     ` Cordes MJ
1996-04-21  0:00       ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox