Meaning of Float>>closeTo:

Frank Shearar frank.shearar at angband.za.org
Fri Mar 2 14:17:57 UTC 2007


"Damien Cassou" <damien.cassou at gmail.com> wrote:

> 2007/3/2, Frank Shearar <frank.shearar at angband.za.org>:
> > "Damien Cassou" <damien.cassou at gmail.com> wrote:
> > > 2007/3/2, Bert Freudenberg <bert at freudenbergs.de>:
> > > > On Mar 2, 2007, at 13:56 , Damien Cassou wrote:
> > > > > 2007/3/2, Bert Freudenberg <bert at freudenbergs.de>:
> > > > >> On Mar 2, 2007, at 12:55 , Damien Cassou wrote:
> > > > >> > 999999 closeTo: 999899.00011.             => true
> > > > >> > 999999 closeTo: 999899.0001.               => false
> > > > >> >
> > > > Huh? Should it answer "maybe"? There is a threshold, and you chose
> > > > your numbers right at that threshold.
> > >
> > > I think the answer should be the same. Look at the differences:
> > >
> > > 999999 - 999899.00011.                          => 99.9998899999773
> > > 999999 - 999899.0001.                            => 99.9999000000535
> > >
> > > It's nearly a hundred in both cases.
> > >
> > > 999999 closeTo: 999899.00011.            => true (with a difference of
> > > nearly 100)
> > > 2 closeTo: 1                                               => false
> > > (with a difference of 1)
> > >
> > > So, what is the threshold ?
> >
> > 0.0001? ( According to Float>>closeTo: )
>
> Ok, so if two numbers have nearly 100 of difference, #closeTo:
> shouldn't answer true. Right ?

Ah, but #closeTo: (on closer reading) doesn't just do |a - b| < threshold.
The idea of "close to" depends on the magnitudes of the numbers involved:
99999 and 999899.00011 are close to each other because their difference
(99.9998899999773) is less than a thousandth of the magnitude of the larger
number (which is 100).

What confused me the first time is that the threshold value (in the sense of
|a-b| < threshold) is the same as the threshold value in the sense of |a-b|
< max(a, b)*threshold.

frank




More information about the Squeak-dev mailing list