Re: [Pharo-users] Rounding in Floats

2020-09-07 Thread Esteban Maringolo
On Tue, Sep 8, 2020 at 12:16 AM Richard O'Keefe wrote: > > "7.1 roundTo: 0.1 should return 7.1" > You're still not getting it. I was until Konrad explained it. > Binary floating point CANNOT represent either of those numbers. > You seem to be assuming that Pharo is making some mistake. > It isn'

Re: [Pharo-users] Rounding in Floats

2020-09-07 Thread Richard O'Keefe
"7.1 roundTo: 0.1 should return 7.1" You're still not getting it. 7.1 IS NOT 71/10. 0.1 IS NOT 1/10. Binary floating point CANNOT represent either of those numbers. You seem to be assuming that Pharo is making some mistake. It isn't. All it is doing is refusing to lie to you. #include #include

Re: [Pharo-users] Rounding in Floats

2020-09-07 Thread Esteban Maringolo
Hi Tomohiro, Thanks, that certainly is the simplest solution that does exactly what I need. Maybe roundTo: should be considered harmful when using Floats. (and it is very unlikely anybody is going to round to something other than a power of 10) Best regards! Esteban A. Maringolo On Mon, Sep 7

Re: [Pharo-users] Rounding in Floats

2020-09-07 Thread Tomohiro Oda
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 : > > Hi Sven, > > On Mon, Sep 7, 2020 at 9:10 AM Sven Van Caekenberghe wrote: > > >

Re: [Pharo-users] Rounding in Floats

2020-09-07 Thread Esteban Maringolo
Hi Sven, On Mon, Sep 7, 2020 at 9:10 AM Sven Van Caekenberghe wrote: > > On 6 Sep 2020, at 22:21, Esteban Maringolo 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 frie

Re: [Pharo-users] Rounding in Floats

2020-09-07 Thread serge . stinckwich
BTW why closeTo: is initialized by default with a value of 0.0001 ? https://github.com/pharo-project/pharo/issues/3067 Sent from my iPhone > On 7 Sep 2020, at 20:10, Sven Van Caekenberghe wrote: > >  > >> On 6 Sep 2020, at 22:21, Esteban Maringolo wrote: >> >> It is not for printing but for

Re: [Pharo-users] Rounding in Floats

2020-09-07 Thread Sven Van Caekenberghe
> On 6 Sep 2020, at 22:21, Esteban Maringolo 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. Floats should always be

Re: [Pharo-users] Rounding in Floats

2020-09-07 Thread Konrad Hinsen
Hi Esteban, > It is not for printing but for testing. I want to assert that a > certain calculation gives the expected result. > And then it fails because of the difference above when it is > "semantically" correct. If you want reliable precision tests with IEEE floats, you should use rounding to

Re: [Pharo-users] Rounding in Floats

2020-09-06 Thread Esteban Maringolo
Hi Sven, On Sun, Sep 6, 2020 at 11:57 AM Sven Van Caekenberghe wrote: > > On 6 Sep 2020, at 16:06, Esteban Maringolo wrote: > > (9.1 + (-2.0)) roundTo: 0.1. > > "7.1005" > > Is this a bug? > > Maybe. > > But I would not approach the problem of rounding like that. > You probably wan

Re: [Pharo-users] Rounding in Floats

2020-09-06 Thread Sven Van Caekenberghe
> On 6 Sep 2020, at 16:06, Esteban Maringolo wrote: > > Hi, > > Continuing with my issues with decimals, I'm having one issue that is > not clear to me why it happens. > > If I do: > (9.1 + (-2.0)) roundTo: 0.1. > "7.1005" > > I expect to get a single decimal Float (rounded with