Typo: FP should read floating point and not fixed point. Steffen Märcker schrieb am Dienstag, 15. Juni 2021 08:47:24 (+02:00):
Have you considered using fixed-point arithmetic? For example: 7.1s2 roundTo: 0.1s2
The rule of thumb I stick to is to use FP only if I know the inaccuracies won't bite me. Funny enough, both 7.1 and 0.1 are already not accurately representable as floats. (And by coincidence, I prepared exam questions about floats for my students yesterday. )
Kind regards, Steffen
Konrad Hinsen schrieb am Dienstag, 15. Juni 2021 07:02:30 (+02:00):
On 15/06/2021 01:03, Esteban Maringolo wrote:
Sure, but what initiated this thread was a reference to roundTo: 0.1 which produced a "wrong" output.
(9.1 + (-2.0)) roundTo: 0.1 "=> 7.1000000000000005" 7.1 roundTo: 0.1 "=> 7.1000000000000005"
However, at this point I know that Pharo "does the right, raw, thing" (at least compared to other mainstream languages), but it still produces a surprise effect.
That's the "floating point surprise" that everyone has at some point, no matter the language and runtime system. If that surprise is a problem for you, are you sure that floating-point arithmetic is what you really want? Maybe your needs are better served with integers and fractions.
Konrad.
-- Gesendet mit Vivaldi Mail. Laden Sie Vivaldi kostenlos von vivaldi.com herunter.
-- Gesendet mit Vivaldi Mail. Laden Sie Vivaldi kostenlos von vivaldi.com herunter.