[Seaside-dev] Troubles with WANumberPrinter>>printFloat:on:

Michael Lucas-Smith mlucas-smith at cincom.com
Thu Jun 4 16:20:09 UTC 2009


Hi All,

I raised this a few months ago, but I'm still having trouble with it. 
Squeak represents Floats as 64bit, while VW represents them as 32bit. 
This causes the printFloat:on: method to lose precision.

An alternate implementation is to scale up the number when printing the 
fraction:

printFloat: aNumber on: aStream
    | multiplier rounded |
    multiplier := base asFloat raisedTo: precision.
    rounded := aNumber roundTo: (accuracy ifNil: [ 1.0 / multiplier ]).
    self printInteger: rounded on: aStream.
    delimiter isNil
        ifFalse: [ aStream nextPut: delimiter ].
    self printFraction: (multiplier * rounded) - (multiplier * rounded 
integerPart) on: aStream

However, even when this is done, some of the test assertions still fail. eg:

self assert: (converter print: 0.99) = '0.99'.

The printed result comes out as 0.98 in this case. There are 5 tests 
that all fail because of this problem.

Here are my concerns:
a) We can't really expect floats to behave this nicely across platforms 
and smalltalks
b) I don't entirely know if my proposed solution is right

Cheers,
Michael


More information about the seaside-dev mailing list