Esteban, You can instead use `7.1 round: 1` to get 7.1. It's not the problem of the rounding algorithm. It's because IEEE float can't express the exact value of 0.1. --- tomo 2020å¹´9æ7æ¥(æ) 21:28 Esteban Maringolo <emaringolo@gmail.com>:
Hi Sven,
On Mon, Sep 7, 2020 at 9:10 AM Sven Van Caekenberghe <sven@stfx.eu> wrote:
On 6 Sep 2020, at 22:21, Esteban Maringolo <emaringolo@gmail.com> wrote:
It is not for printing but for testing. I want to assert that a certain calculation gives the expected result.
Then you should use #assert:closeTo: and friends. (9.1 + (-2.0)) closeTo: 7.1 precision: 0.1.
I remembered about it, and implemented my own #assertDifferential:equals: which I first did convert to ScaledDecimals and then compares with #roundedByScale.
Floats should always be compared using an epsilon (precision) value in tests, not using equality.
Sure, but 7.1 roundTo: 0.1 should return 7.1. Shouldn't it?
Regards!
Esteban A. Maringolo