[squeak-dev] The Inbox: Kernel-mtf.924.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Sat May 2 20:13:11 UTC 2015


2015-05-02 18:27 GMT+02:00 <commits at source.squeak.org>:

> A new version of Kernel was added to project The Inbox:
> http://source.squeak.org/inbox/Kernel-mtf.924.mcz
>
> ==================== Summary ====================
>
> Name: Kernel-mtf.924
> Author: mtf
> Time: 2 May 2015, 12:26:05.675 pm
> UUID: 7f688860-5202-4c0d-8ece-8723fe7317d6
> Ancestors: Kernel-nice.923
>
> Copied Number >> #round: from Pharo. One of 3 methods needed to make the
> Artefact pdf library work on squeak:
> https://sites.google.com/site/artefactpdf/
>
> =============== Diff against Kernel-nice.923 ===============
>
> Item was added:
> + ----- Method: Float>>round: (in category 'truncation and round off')
> -----
> + round: numberOfWishedDecimal
> +         "only leave a fixed amount of decimal"
> +         "10.12345 round: 2 => 10.12"
> +
> +         | v |
> +         v := 10 raisedTo: numberOfWishedDecimal.
> +         ^ ((self * v) rounded / v) asFloat
> + !
>
>
self assert: (Float fmax round: 2) = Float fmax.

It's probably not very important for artefact, but if this method has a
wider usage than artefact, then it should better be robust to overflow...


> Item was added:
> + ----- Method: Fraction>>round: (in category 'truncation and round off')
> -----
> + round: numberOfWishedDecimal
> +       ^self asFloat round: numberOfWishedDecimal!
>
>
Transforming exact arithmetic into inexact Float sounds like heresy to me ;)
That's a questionable choice.
Why this cult to Float would be necessary here?


> Item was added:
> + ----- Method: Integer>>round: (in category 'truncation and round off')
> -----
> + round: numberOfWishedDecimal
> +       ^self!
>
> Item was added:
> + ----- Method: Number>>round: (in category 'truncation and round off')
> -----
> + round: numberOfWishedDecimal
> +       self subclassResponsibility!
>
>
> If it's subclass responsibility, then it must be implemented in
ScaledDecimal.
This is not necessary in Pharo, because ScaledDecimal has been moved under
Fraction, but it is in Squeak.
I'd rather see Float implementation moved up (without the asFloat) and
Float invoking super asFloat...

I didn't check artefact, but I suspect that the usage is just to
printShowingMaxDecimals: numberOfWishedDecimal, which would make the whole
method moot.

Nicolas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20150502/276d4759/attachment.htm


More information about the Squeak-dev mailing list