[Pharo-project] Unexpected behavior of roundTo:
Nicolas Cellier
nicolas.cellier.aka.nice at gmail.com
Fri Apr 8 19:41:36 CEST 2011
2011/4/8 Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>:
> Once more, Floats are inexact.
> 0.01 ~= 0.01s2
> The name #absPrintExactlyOn:base: is lying, it does not print exactly,
> but it prints the shortest decimal representation than will be rounded
> to the same Float when read back.
>
> To print it exactly, you need to use #printShowingDecimalPlaces: indeed.
> As every finite Float is a represented internally as a Fraction with a
> denominator being a power of 2, every finite Float has a decimal
> representation with a finite number of decimals digits (just multiply
> numerator and denominator with adequate power of 5, and you'll get the
> digits).
>
> So try:
> 0.01 printShowingDecimalPlaces: 59
> -> 0.01000000000000000020816681711721685132943093776702880859375
>
Oh one thing I forgot, you wanna know how many digits you need after
decimal point to print exactly ?
Easy, (0.01 asTrueFraction denominator highBit - 1).
Nicolas
More information about the Pharo-project
mailing list