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

Re: Comparing Int and Num

Thread Previous
From:
Parrot Raiser
Date:
April 14, 2021 13:56
Subject:
Re: Comparing Int and Num
Message ID:
CACwLAp8MDVjTG8ssZiwL4eA2pDeYtMYaOW9V9G2EYvF7QAO6Fw@mail.gmail.com
What do these enormous numbers represent?

On 4/13/21, 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


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