|
Matias,
> Hi: I don't know if this only happened on mi PC, but I evaluate:
> 123456.456 fractionPart
> And I get: 0.456000000005588.
> I'm using Dolphin 6.02
You will see similar things occurring for Floating point values in all
languages. Decimal floats cannot always be expressed accurately in a
binary system, there will always be a point below which the inaccuracies
will become evident. This is normally hidden but some operations, as
above, can result in the inaccuracy becoming visible.
As long as you are aware of this it doesn't cause too may problems.
There most common problem is comparison. If you evaluate
123456.456 fractionPart = 0.456
the answer is false. Dolphin provides a method to get around this, one
that is aware of the limitations of Float representation.
123456.456 fractionPart equals: 0.456
will answer true. You can also enforce a precision yourself, which may
be easier as #equals: is not polymorphic across all Numbers
(123456.456 fractionPart roundTo: 0.0001) = 0.456
answers true
--
Ian
Use the Reply-To address to contact me (limited validity).
Mail sent to the From address is ignored.
|