Raku / old-issue-tracker

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

Inconsistencies and Bugs in Native Types Behaviours #5099

Open p6rt opened 8 years ago

p6rt commented 8 years ago

Migrated from rt.perl.org#127409 (status was 'new')

Searchable as RT127409$

p6rt commented 8 years ago

From @zoffixznet

*** Note​: I started writing this, but when I got to uint8, I realized it was taking too much time, so I gave up; this is a partial report*** ********************************************************************************************************************************************

There are some inconsistencies with the behaviours among the native types, including buggy behaviour of postdecrement/increment ops when the increment/decrement would make underflow/overflow occur.

Here's the summary table. Detailed code executes are in the attachment.

The meaning of headers​:   Assigning Too-Low Value​: assigning value below one a type can hold, such as -1 to an unsigned type   Assigning Too-High Value​: same as above, except too high a value, such as a 50-bit value into int32   Underflow works​: decrementing past lowest value flips over to the other end, such as decrementing a 0 on uint8 gives 256   Overflow works​: same as above, except on the upper bounder, such as incrementing 256 on uint8 gives 0   Post-[de/in]cremnent on overflow works​: best shown in an example​:

  WORKS​: we flipped over the boundary and increment/decrement operation happened just once, returning the unmodified value in the second say()​:   \ m​: my int $x = 2**63 - 1; say $x; say $x++; say $x   \ rakudo-moar 780192​: OUTPUT«9223372036854775807␤9223372036854775807␤-9223372036854775808␤»   \ m​: my int $x = -2**63; say $x; say $x--; say $x   \ rakudo-moar 780192​: OUTPUT«-9223372036854775808␤-9223372036854775808␤9223372036854775807␤»

  BROKEN​: operation happens TWICE and second say() behaves as if it were a prefix increment/decrement​:   \ m​: my int32 $x = 2**31 - 1; say $x; say $x++; say $x;   \ rakudo-moar 780192​: OUTPUT«2147483647␤-2147483649␤-2147483648␤»   \ m​: my int32 $x = -2**31; say $x; say $x--; say $x;   \ rakudo-moar 780192​: OUTPUT«-2147483648␤2147483648␤2147483647␤»

And here's the table showing the results of my evaluation​:

[Type] [Assigning Too-Low Value] [Assigning Too-High Value] [Underflow works] [Overflow works] [Post-[de/in]crement on overflow works] int Runtime error Runtime error Yes Yes Yes int8 Value=0 Value=0 Yes Yes NO int16 Value=0 Value=0 Yes Yes NO int32 Value=0 Value=0 Yes Yes NO int64 Runtime error Runtime error Yes Yes Yes uint Behaves as int Behaves as int No (behaves as int) No (behaves as int) Yes (but behaves as int) uint8 Value rolls over Value rolls over No $x -= 1 works, but No $x +=1 work, but   --$x gives negatives ++$x goes over 255

byte uint16 uint32 uint64 num num32 num64

p6rt commented 8 years ago

From @zoffixznet

int assigning too high/low value​: \ m​: my int $x = 2**100; say $x \ rakudo-moar 780192​: OUTPUT«Cannot unbox 101 bit wide bigint into native integer? in block \ at /tmp/pVQy7K7HIo line 1??» \ m​: my int8 $x = -2**100; say $x \ rakudo-moar 780192​: OUTPUT«Cannot unbox 101 bit wide bigint into native integer? in block \ at /tmp/D57OVre76N line 1??»

int underflow works​: \ m​: my int $x = -2**63; say $x \ rakudo-moar 780192​: OUTPUT«-9223372036854775808?» \ m​: my int $x = -2**63; --$x; say $x \ rakudo-moar 780192​: OUTPUT«9223372036854775807?»

int overflow works​: \ m​: my int $x = 2**63 - 1; say $x \ rakudo-moar 780192​: OUTPUT«9223372036854775807?» \ m​: my int $x = 2**63 - 1; ++$x; say $x \ rakudo-moar 780192​: OUTPUT«-9223372036854775808?»

int postop works​: \ m​: my int $x = 2**63 - 1; say $x; say $x++; say $x \ rakudo-moar 780192​: OUTPUT«9223372036854775807?9223372036854775807?-9223372036854775808?» \ m​: my int $x = -2**63; say $x; say $x--; say $x \ rakudo-moar 780192​: OUTPUT«-9223372036854775808?-9223372036854775808?9223372036854775807?»

int8 assigning too high/low value​: \ m​: my int8 $x = -2**60; say $x \ rakudo-moar 780192​: OUTPUT«0?» \ m​: my int8 $x = 2**60; say $x \ rakudo-moar 780192​: OUTPUT«0?»

int8 underflow works​: \ m​: my int8 $x = -2**7; say $x \ rakudo-moar 780192​: OUTPUT«-128?» \ m​: my int8 $x = -2**7; --$x; say $x \ rakudo-moar 780192​: OUTPUT«127?»

int8 overflow works​: \ m​: my int8 $x = 2**7-1; say $x \ rakudo-moar 780192​: OUTPUT«127?» \ m​: my int8 $x = 2**7-1; ++$x; say $x \ rakudo-moar 780192​: OUTPUT«-128?»

int8 postop does NOT work (behaves as if it were ++$x and --$x, AND operation happens twice)​: \ m​: my int8 $x = -2**7; say $x; say $x--; say $x \ rakudo-moar 780192​: OUTPUT«-128?128?127?» \ m​: my int8 $x = 2**7 - 1; say $x; say $x++; say $x \ rakudo-moar 780192​: OUTPUT«127?-129?-128?»

int16 underflow works​: \ m​: my int16 $x = -2**15; say $x; \ rakudo-moar 780192​: OUTPUT«-32768?» \ m​: my int16 $x = -2**15; --$x; say $x; \ rakudo-moar 780192​: OUTPUT«32767?»

int16 assigning too high/low value​: \ m​: my int16 $x = -2**60; say $x \ rakudo-moar 780192​: OUTPUT«0?» \ m​: my int16 $x = 2**60; say $x \ rakudo-moar 780192​: OUTPUT«0?»

int16 overflow works​: \ m​: my int16 $x = 2**15 - 1; say $x; \ rakudo-moar 780192​: OUTPUT«32767?» \ m​: my int16 $x = 2**15 - 1; ++$x; say $x; \ rakudo-moar 780192​: OUTPUT«-32768?»

int16 postop does NOT work (behaves as if it were ++$x and --$x, AND operation happens twice)​: \ m​: my int16 $x = 2**15 - 1; say $x; say $x++; say $x; \ rakudo-moar 780192​: OUTPUT«32767?-32769?-32768?» \ m​: my int16 $x = -2**15; say $x; say $x--; say $x; \ rakudo-moar 780192​: OUTPUT«-32768?32768?32767?»

int32 assigning too high/low value​: \ m​: my int32 $x = -2**60; say $x \ rakudo-moar 780192​: OUTPUT«0?» \ m​: my int32 $x = 2**60; say $x \ rakudo-moar 780192​: OUTPUT«0?»

int32 underflow works​: \ m​: my int32 $x = -2**31; say $x; \ rakudo-moar 780192​: OUTPUT«-2147483648?» \ m​: my int32 $x = -2**31; --$x; say $x; \ rakudo-moar 780192​: OUTPUT«2147483647?»

int32 overflow works​: \ m​: my int32 $x = 2**31 - 1; say $x; \ rakudo-moar 780192​: OUTPUT«2147483647?» \ m​: my int32 $x = 2**31 - 1; $x++; say $x; \ rakudo-moar 780192​: OUTPUT«-2147483648?»

int32 postop does NOT work (behaves as if it were ++$x and --$x, AND operation happens twice)​: \ m​: my int32 $x = 2**31 - 1; say $x; say $x++; say $x; \ rakudo-moar 780192​: OUTPUT«2147483647?-2147483649?-2147483648?» \ m​: my int32 $x = -2**31; say $x; say $x--; say $x; \ rakudo-moar 780192​: OUTPUT«-2147483648?2147483648?2147483647?»

int64 assigning too high/low value​: \ m​: my int64 $x = -2**100; say $x \ rakudo-moar 780192​: OUTPUT«Cannot unbox 101 bit wide bigint into native integer? in block \ at /tmp/H2Wp75nKB8 line 1??» \ m​: my int64 $x = 2**100; say $x \ rakudo-moar 780192​: OUTPUT«Cannot unbox 101 bit wide bigint into native integer? in block \ at /tmp/GO5Ce9tN1m line 1??»

int64 underflow works​: \ m​: my int64 $x = -2**63; say $x; \ rakudo-moar 780192​: OUTPUT«-9223372036854775808?» \ m​: my int64 $x = -2**63; --$x; say $x; \ rakudo-moar 780192​: OUTPUT«9223372036854775807?»

int64 overflow works​: \ m​: my int64 $x = 2**63 - 1; say $x; \ rakudo-moar 780192​: OUTPUT«9223372036854775807?» \ m​: my int64 $x = 2**63 - 1; ++$x; say $x; \ rakudo-moar 780192​: OUTPUT«-9223372036854775808?»

int64 postop works​: \ m​: my int64 $x = 2**63 - 1; say $x; say $x++; say $x; \ rakudo-moar 780192​: OUTPUT«9223372036854775807?9223372036854775807?-9223372036854775808?» \ m​: my int64 $x = -2**63; say $x; say $x--; say $x; \ rakudo-moar 780192​: OUTPUT«-9223372036854775808?-9223372036854775808?9223372036854775807?»

uint assigning too high/low value​: \ m​: my uint $x = -100; say $x \ rakudo-moar 780192​: OUTPUT«-100?» \ m​: my uint $x = 2**63; say $x \ rakudo-moar 780192​: OUTPUT«-9223372036854775808?» \ m​: my uint $x = 2**100; say $x \ rakudo-moar 780192​: OUTPUT«Cannot unbox 101 bit wide bigint into native integer? in block \ at /tmp/BVOc4q6THL line 1??» \ m​: my uint $x = -2**100; say $x \ rakudo-moar 780192​: OUTPUT«Cannot unbox 101 bit wide bigint into native integer? in block \ at /tmp/LKnA6GYHaK line 1??»

uint underflow behaves like int​: \ m​: my uint $x = 0; say $x \ rakudo-moar 780192​: OUTPUT«0?» \ m​: my uint $x = 0; --$x; say $x \ rakudo-moar 780192​: OUTPUT«-1?»

uint overflow behaves like int​: \ m​: my uint $x = 2**63; say $x \ rakudo-moar 780192​: OUTPUT«-9223372036854775808?» \ m​: my uint $x = 2**63; ++$x; say $x \ rakudo-moar 780192​: OUTPUT«-9223372036854775807?»

uint postop works (but behaves like int)​: \ m​: my uint $x = 0; say $x; say $x--; say $x \ rakudo-moar 780192​: OUTPUT«0?0?-1?» \ m​: my uint $x = 2**63; say $x; say $x++; say $x \ rakudo-moar 780192​: OUTPUT«-9223372036854775808?-9223372036854775808?-9223372036854775807?»

uint8 assigning too high/low value​: \ m​: my uint8 $x = -100; say $x \ rakudo-moar 780192​: OUTPUT«156?» \ m​: my uint8 $x = -300; say $x \ rakudo-moar 780192​: OUTPUT«212?» \ m​: my uint8 $x = 300; say $x \ rakudo-moar 780192​: OUTPUT«44?»

uint underflow works​: uint overflow works​: uint postop works​:

uint assigning too high/low value​: uint underflow works​: uint overflow works​: uint postop works​:

uint assigning too high/low value​: uint underflow works​: uint overflow works​: uint postop works​:

uint assigning too high/low value​: uint underflow works​: uint overflow works​: uint postop works​:

uint assigning too high/low value​: uint underflow works​: uint overflow works​: uint postop works​:

uint assigning too high/low value​: uint underflow works​: uint overflow works​: uint postop works​:

uint assigning too high/low value​: uint underflow works​: uint overflow works​: uint postop works​:

p6rt commented 8 years ago

From @zoffixznet

Related​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=127144 https://rt-archive.perl.org/perl6/Ticket/Display.html?id=124088