2016-10-31 22:49 GMT+01:00 John Brant <brant@refactoryworkers.com>:
On Oct 31, 2016, at 3:58 PM, Martin McClure <martin@hand2mouse.com> wrote:
(1.19 roundTo: (1/10))asFloat
I should note that the final example *should* result in a Float without having to have #asFloat sent to it. Per ANSI and traditional Smalltalk practice, any operation where the receiver *or* the argument is a Float produces a Float.
While ANSI says that the numbers should be converted using the default conversion table, all of the Smalltalkâs that Iâve tried donât follow that. Iâve tried Dolphin, VW, Pharo, & VAST, and all return fractions. I prefer this behavior over the ANSI behavior.
John Brant
Whatever result species, don't trust (aFloat roundTo: aFraction) too much, they have some chances to be inexact, except for trivial powers of two. Example: (1.105 roundTo: 1/100) -> (111/100) 1.105 < (1105/1000) -> true Though the number was smaller than exact tie (in decimal), it was rounded up. Indeed, the exact computations have a different opinion: (1.105 asFraction roundTo: 1/100) -> (11/10) That's why we must implement round: with exact computations...