develooper Front page | perl.perl6.users | Postings from May 2021

Re: Comparing Int and Num

Thread Previous | Thread Next
From:
Elizabeth Mattijsen
Date:
May 3, 2021 16:34
Subject:
Re: Comparing Int and Num
Message ID:
5E184188-BD98-4C33-8D1A-6875074BF5D2@dijkmat.nl
[16:37:23] <MasterDuke>	i'm not subscribed to the mailing list but maybe someone who is could chime in to this thread https://www.nntp.perl.org/group/perl.perl6.users/2021/04/msg9878.html  and mention that i believe the problem is in libtommath's mp_get_double and the gmp branch fixes it?

> On 14 Apr 2021, at 04:09, sisyphus <sisyphus359@gmail.com> wrote:
> 
> Hi,
> 
> C:\>raku -e "say 1.8446744073709552e+19 == 18446744073709551615"
> True
> 
> I think I understand why raku deems this to be true.
> The LHS is 0x1p+64, which is identical to the double that the RHS rounds to.
> (AFAIK, it's the same with perl5 and C.)
> 
> Of course, for all $x in the Int range of  18446744073709551615 - 1023 to  18446744073709551615, we find that "1.8446744073709552e+19 == $x" is True, because each of those $x Int values round to 0x1p+64.
> I understand all of that (I think).
> 
> What I don't understand is the following:
> 
> C:\>raku -e "say 1.8446744073709552e+19 == (18446744073709551615 - 1024)"
> True
> 
> C:\>raku -e "say 1.8446744073709552e+19 == (18446744073709551615 - 1087)"
> True
> 
> For those particular Int values (and all Int values in between) the RHS rounds to 0x1.fffffffffffffp+63,
> and the result should therefore be "False" ... but it is reported as "True".
> 
> It's not until we subtract at least 1088 that the behaviour I'm expecting appears:
> 
> C:\>raku -e "say 1.8446744073709552e+19 == (18446744073709551615 - 1088)"
> False
> 
> Comparing the RHS Int values given in the last 2 one liners, I find they are (respectively):
> 0.1111111111111111111111111111111111111111111111111111101111000000E64
> 0.1111111111111111111111111111111111111111111111111111101110111111E64
> 
> It's not apparent to me how those 2 integer values can round to different doubles.
> Those 2 integer values can also be written as (respectively):
> 18446744073709550528
> 18446744073709550527
> 
> On Windows, I have:
> C:\>raku --version
> This is Rakudo version 2020.05.1 built on MoarVM version 2020.05
> implementing Raku 6.d.
> 
> On Ubuntu, I have:
> $ raku --version
> Welcome to Rakudo(tm) v2021.03.
> Implementing the Raku(tm) programming language v6.d.
> Built on MoarVM version 2021.03.
> 
> It's the same behaviour on both systems.
> 
> Is this a bug that I ought to report ?
> 
> Cheers,
> Rob  
> 
> 
> 
> 
> 
> 


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About