Currently, Whiley does not have an unsigned bitwise shift operator. This is quite interesting! For example, the following is problematic:
public function to_int(byte b) -> int:
int r = 0
int base = 1
while b != 0b:
if (b & 0b00000001) == 0b00000001:
r = r + base
b = b >> 1
base = base * 2
// finally, add the sign
if r >= 128:
return -(256-r)
else:
return r
This goes into an infinite loop when b on entry represents a negative number. The problem is that 0b11111111 >> 1 leaves 0b11111111 !!
This was actually a bug in the standard library that was picked up by QuickCheck. Therefore, we could really do with an operator such as >>> found in Java.
Currently, Whiley does not have an unsigned bitwise shift operator. This is quite interesting! For example, the following is problematic:
This goes into an infinite loop when
b
on entry represents a negative number. The problem is that0b11111111 >> 1
leaves0b11111111
!!This was actually a bug in the standard library that was picked up by QuickCheck. Therefore, we could really do with an operator such as
>>>
found in Java.