Inconsistent signed/unsigned results in right shift

Hi all,

It seems that (-1)>>(1<<32) and (-1)>>(1<<64) produces inconsistent results (at least with SWI 8.0.3). This is probably due to the transition between small and large integer representations (we are fixing the same bug in Ciao right now). See log attached.

Cheers,
Jose

Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.3)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- X is 1 >> (1<<32).
X = 0.

?- X is 1 >> (1<<64).
X = 0.

?- X is 1 >> (1<<128).
X = 0.

?- X is (-1) >> (1<<128).
X = 0.

?- X is (-1) >> (1<<64).
X = 0.

?- X is (-1) >> (1<<32).
X = -1.

?- X is (-1) >> (1<<16).
X = -1.

?- 
1 Like

By my system are you referring to the machine you are using or Jekejeke Prolog

See edited post.

I noticed that the examples were run with
SWI-Prolog (threaded, 64 bits, version 8.0.3) so I decided to try the latest version
SWI-Prolog (threaded, 64 bits, version 8.1.19-43-ge65571d98)

The results are the same except for

?- X is (-1) >> (1<<32).
X = 0.
Test cases. Click triangle to expand.
:- begin_tests(bit_shift).

test(100) :-
    X is 1 >> (1<<16),
    assertion( X == 0 ).

test(200) :-
    X is 1 >> (1<<32),
    assertion( X == 0 ).

test(300) :-
    X is 1 >> (1<<64),
    assertion( X == 0 ).

test(400) :-
    X is 1 >> (1<<128),
    assertion( X == 0 ).

test(600) :-
    X is (-1) >> (1<<16),
    assertion( X == -1 ).

test(700) :-
    X is (-1) >> (1<<32),
    assertion( X == 0 ).

test(800) :-
    X is (-1) >> (1<<64),
    assertion( X == 0 ).

test(900) :-
    X is (-1) >> (1<<128),
    assertion( X == 0 ).

:- end_tests(bit_shift).