[squeak-dev] FloatArray gives unexpected results with float numbers.

Philippe Marschall philippe.marschall at gmail.com
Sun Dec 21 09:13:42 UTC 2008


2008/12/21 James Foster <Smalltalk at jgfoster.net>:
> On Dec 20, 2008, at 5:54 PM, Nikolay Suslov wrote:
>
>> Hello,
>>
>> It is a bug.. or?
>
> A misunderstanding.
>
>> FloatArray newFrom: {0.938611557944869}.
>> Expecting result is the entered float number, but evaluating gives - a
>> FloatArray(0.938611567020416).
>
> Float has the following class comment: "My instances represent IEEE-754
> floating-point double-precision numbers."
> FloatArray has the following class comment: "FloatArrays store 32bit IEEE
> floating point numbers."
>
> I think what you are seeing is the conversion of 64-bit floating point to
> 32-bit floating point. Sorry for the initial confusion about your expected
> result.

Even it that wouldn't be the case it would still be floating point
numbers and imprecise by design. Additionally not every decimal number
can be represented by a floating point number.

Cheers
Philippe



More information about the Squeak-dev mailing list