diff options
Diffstat (limited to 'testes')
-rw-r--r-- | testes/bitwise.lua | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/testes/bitwise.lua b/testes/bitwise.lua index 9509f7f0..dd0a1a9a 100644 --- a/testes/bitwise.lua +++ b/testes/bitwise.lua | |||
@@ -38,6 +38,18 @@ d = d << 32 | |||
38 | assert(a | b ~ c & d == 0xF4000000 << 32) | 38 | assert(a | b ~ c & d == 0xF4000000 << 32) |
39 | assert(~~a == a and ~a == -1 ~ a and -d == ~d + 1) | 39 | assert(~~a == a and ~a == -1 ~ a and -d == ~d + 1) |
40 | 40 | ||
41 | |||
42 | do -- constant folding | ||
43 | local code = string.format("return -1 >> %d", math.maxinteger) | ||
44 | assert(load(code)() == 0) | ||
45 | local code = string.format("return -1 >> %d", math.mininteger) | ||
46 | assert(load(code)() == 0) | ||
47 | local code = string.format("return -1 << %d", math.maxinteger) | ||
48 | assert(load(code)() == 0) | ||
49 | local code = string.format("return -1 << %d", math.mininteger) | ||
50 | assert(load(code)() == 0) | ||
51 | end | ||
52 | |||
41 | assert(-1 >> 1 == (1 << (numbits - 1)) - 1 and 1 << 31 == 0x80000000) | 53 | assert(-1 >> 1 == (1 << (numbits - 1)) - 1 and 1 << 31 == 0x80000000) |
42 | assert(-1 >> (numbits - 1) == 1) | 54 | assert(-1 >> (numbits - 1) == 1) |
43 | assert(-1 >> numbits == 0 and | 55 | assert(-1 >> numbits == 0 and |