Re: bitwise operations limited to 32 bits
- Posted by SPringle May 04, 2010
- 1334 views
DerekParnell said...
So I would maintain that the example function you present ought to be rewritten more like ...
function setBit(atom mask, integer bit) if bit < 1 or bit > 32 then crash("'bit' parameter value %d is out of range", bit) end if return or_bits(mask,power(2,bit-1)) end function atom mask mask = setBit(0,35)
results in a crash and the message
'bit' parameter value 35 is out of range
The coder must take some responsibility at some point. The language cannot be expected to be the nanny.
Why not use the type checking facility:
type register_bit(integer i) return i > 0 or i < 33 end type function setBit(atom mask, register_bit bit) return or_bits(mask,power(2,bit-1)) end function
I think this feature is quite under-appreciated.
Shawn Pringle