Files
mercury/tests/hard_coded/shift_test.exp
Simon Taylor d38f9f8bee Change the bit shift functions to perform checking to avoid
Estimated hours taken: 1

Change the bit shift functions to perform checking to avoid
implementation defined behaviour.

library/int.m:
	Add checking to `int:<<' and `int:>>'.
	Add `int:unchecked_left_shift' and `int:unchecked_right_shift'
	which do not perform any checking.

compiler/code_util.m:
	Replace `int:<<' and `int:>>' with `int:unchecked_left_shift' and
	`int:unchecked_right_shift' in the builtin table.

NEWS:
	Mention the changes to int.m.

tests/hard_coded/Mmakefile:
tests/hard_coded/shift_test.m:
tests/hard_coded/shift_test.exp:
	Test the shift functions.
1999-03-22 00:33:54 +00:00

31 lines
666 B
Plaintext

64 << 0 = 64 (64)
64 << 2 = 256 (256)
-64 << 2 = -256 (-256)
64 << -2 = 16 (16)
-64 << -2 = -16 (-16)
64 << -256 = 0 (0)
-64 << -256 = -1 (-1)
25 << 3 = 200 (200)
-25 << 3 = -200 (-200)
25 << -3 = 3 (3)
-25 << -3 = -4 (-4)
64 >> 0 = 64 (64)
64 >> 2 = 16 (16)
-64 >> 2 = -16 (-16)
64 >> -2 = 256 (256)
-64 >> -2 = -256 (-256)
64 >> 256 = 0 (0)
-64 >> 256 = -1 (-1)
25 >> 3 = 3 (3)
-25 >> 3 = -4 (-4)
25 >> -3 = 200 (200)
-25 >> -3 = -200 (-200)
64 unchecked_left_shift 2 = 256 (256)
-64 unchecked_right_shift 2 = -16 (-16)
The following cases test undefined behaviour
(they cause overflow):
64 << 256 = 0 (0)
-64 << 256 = 0 (0)
64 >> -256 = 0 (0)
-64 >> -256 = 0 (0)