[squeak-dev] Is there a better implementation of Floats?

cdrick cdrick65 at gmail.com
Wed Apr 9 16:00:58 UTC 2008


> > 1 - 0.2 -0.05 -0.3 -0.1= 0.35  "true"
> > 1 - 0.2 -0.05 -0.3 -0.1 - 0.10= 0.25  "*****false*****"
> > 1 - 0.2 -0.05 -0.3 -0.1 - 0.10= 0.24999999999999995   "true "
> > and i add the following examples:
> > 0.35 - 0.0 = 0.35 "true"
> > 0.35 - 0.1 = 0.25 "false"


There was an interesting discussion around this aspect of float
recently after I noticed this results.

http://lists.squeakfoundation.org/pipermail/beginners/2008-February/003816.html

Cédrick



> >
>
>  This is an intrinsic property of Floats, not specific to Squeak. It's how
> floating point numbers work in your processor. Google "0.1 floating point"
> if you want to know more.
>
>
> > Is there a better implementation of Floats?
> >
>
>  Depending on your definition of "better" you might consider ScaledDecimals:
>
>  0.35s2 - 0.1s2 = 0.25s2
>
>  (in this example with 2 digits of precision)
>
>  - Bert -
>
>
>
>


More information about the Squeak-dev mailing list