Code: Select all
msgbox, % (2 ** 63 == 2 ** 64) ;2 ** 64 should be 0
;workaround: just don't do it
x := 2 ** 63 ;the negative bit
msgbox, % (x == 9223372036854775808 OR x == 0x8000000000000000) ; 2 ** 63 = bin:1000000000..., but 9223372.. and 0x8000.. round down to bin:011111111...
;workaround:
; msgbox, % (x == -9223372036854775808 OR x == -0x8000000000000000)
x := 2 ** 63
msgbox, % (x >> 1 == 2 ** 62) ;when shifting bits right, the negative bit doesn't move (e.g. 1000000.. >> 1 = 1100000..) shifting left works just fine, though
;workaround:
; x >>= 1
; if(x < 0)
; x ^= 2 ** 63
; msgbox, % (x == 2 ** 62)
;EDIT: additional point: getting the last n bits of a number
x := 2 ** 63 | 2 ** 6 | 2 ** 5 | 2 ** 0
msgbox, % Mod(x, 2 ** 6) ;100...001100001 makes all 0's between the first bit and 1100001 1's
;workarounds:
; Mod(x & 0x7FFFFFFFFFFFFFFF, 2 ** 6) ;remove negative bit, assumes at least 1 bit is being removed
; or
; toBin(x & 0x3F) ;bitwise AND with a number with n 1's where n is the amount of digits to keep, not very intuitive
*note: I am aware that format("{:u}", num) displays numbers as if they were unsigned, but it does nothing to solve the screwyness when operations are applied.
Thanks AutoHotkey gods