Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

bitwise shift is inconsistent on int #4341

Open p6rt opened 9 years ago

p6rt commented 9 years ago

Migrated from rt.perl.org#125466 (status was 'open')

Searchable as RT125466$

p6rt commented 9 years ago

From @tux

$ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 16' -9223372036854775808 -140737488355328 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 32' -9223372036854775808 -2147483648 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 63' -9223372036854775808 -1 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 64' -9223372036854775808 -9223372036854775808 \<===== plain wrong $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> -32' -9223372036854775808 -39614081257132168796771975168 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> -64' -9223372036854775808 -170141183460469231731687303715884105728

$ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 16' 9223372036854775807 140737488355327 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 32' 9223372036854775807 2147483647 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 63' 9223372036854775807 0 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 64' 9223372036854775807 9223372036854775807 \<= PLAIN WRONG $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> -2' 9223372036854775807 36893488147419103228 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> -32' 9223372036854775807 39614081257132168792477007872 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +\< 2' 9223372036854775807 -4 \<= WHAT? $ perl6 -e'my int $i = int.Range.max; say $i; say $i +\< -2' 9223372036854775807 2305843009213693951

p6rt commented 7 years ago

From @AlexDaniel

Plain-wrongs and WHATs print different results today. Bisectable points at https://github.com/rakudo/rakudo/commit/242baf256a210f1cb643cb6324916dbc76184c9f

I think we now only need tests for this ticket.

On 2015-06-23 09​:05​:43, hmbrand wrote​:

$ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 16' -9223372036854775808 -140737488355328 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 32' -9223372036854775808 -2147483648 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 63' -9223372036854775808 -1 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 64' -9223372036854775808 -9223372036854775808 \<===== plain wrong $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> -32' -9223372036854775808 -39614081257132168796771975168 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> -64' -9223372036854775808 -170141183460469231731687303715884105728

$ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 16' 9223372036854775807 140737488355327 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 32' 9223372036854775807 2147483647 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 63' 9223372036854775807 0 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 64' 9223372036854775807 9223372036854775807 \<= PLAIN WRONG $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> -2' 9223372036854775807 36893488147419103228 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> -32' 9223372036854775807 39614081257132168792477007872 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +\< 2' 9223372036854775807 -4 \<= WHAT? $ perl6 -e'my int $i = int.Range.max; say $i; say $i +\< -2' 9223372036854775807 2305843009213693951

p6rt commented 7 years ago

The RT System itself - Status changed from 'new' to 'open'

p6rt commented 7 years ago

From @zoffixznet

On Sun, 17 Sep 2017 15​:17​:47 -0700, alex.jakimenko@​gmail.com wrote​:

Plain-wrongs and WHATs print different results today. Bisectable points at https://github.com/rakudo/rakudo/commit/242baf256a210f1cb643cb6324916dbc76184c9f

I think we now only need tests for this ticket.

On 2015-06-23 09​:05​:43, hmbrand wrote​:

$ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 16' -9223372036854775808 -140737488355328 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 32' -9223372036854775808 -2147483648 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 63' -9223372036854775808 -1 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> 64' -9223372036854775808 -9223372036854775808 \<===== plain wrong $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> -32' -9223372036854775808 -39614081257132168796771975168 $ perl6 -e'my int $i = int.Range.min; say $i; say $i +> -64' -9223372036854775808 -170141183460469231731687303715884105728

$ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 16' 9223372036854775807 140737488355327 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 32' 9223372036854775807 2147483647 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 63' 9223372036854775807 0 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> 64' 9223372036854775807 9223372036854775807 \<= PLAIN WRONG $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> -2' 9223372036854775807 36893488147419103228 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +> -32' 9223372036854775807 39614081257132168792477007872 $ perl6 -e'my int $i = int.Range.max; say $i; say $i +\< 2' 9223372036854775807 -4 \<= WHAT? $ perl6 -e'my int $i = int.Range.max; say $i; say $i +\< -2' 9223372036854775807 2305843009213693951

For some of these that OP pointed out as questionable I get the same results as in C. For others, the bug still exists, where it just returns an Int instead of overflowing​: https://irclog.perlgeek.de/perl6/2017-10-08#i_15272553

p6rt commented 7 years ago

From @zoffixznet

Tests were added in https://github.com/perl6/roast/pull/344/files

There are three fudges where it's unknown what the proper behaviour should be (overflow or switch to Int?).

Someone Who Knows should review them and unfudge/correct.

p6rt commented 6 years ago

From @zoffixznet

On Sat, 07 Oct 2017 23​:35​:26 -0700, cpan@​zoffix.com wrote​:

Tests were added in https://github.com/perl6/roast/pull/344/files

There are three fudges where it's unknown what the proper behaviour should be (overflow or switch to Int?).

Someone Who Knows should review them and unfudge/correct.

Some comments on this​: https://irclog.perlgeek.de/perl6-dev/2018-03-05#i_15887265

  * TimToady thinks people who are writing crypto codes want ways to keep everything native, if we make it default the other way