[squeak-dev] Is there a better implementation of Floats?
Bert Freudenberg
bert at freudenbergs.de
Wed Apr 9 15:44:53 UTC 2008
On 09.04.2008, at 07:03, Bernd Elkemann wrote:
> Hi
> i am very impressed by squeaks handling of large integers
> (LargePositiveInteger and resulting from that the Fraction-class).
> However i was disappointed about the small number of digits of Floats
> so my first question is: is there a possibility to increase it?
> the second thing is: i found these examples on the squeak newbee
> group.
> 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"
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
|