Posted 21 July 2015 - 06:30 PM
When the bit api changed up in CC1.74, it became a bit less useful and even break various functions:
All functions will limit the number to the range of a signed 32bit number, but give numbers that are unsigned 32bit numbers.
And by limit to a range, it'll do something more like
This will for example, break colors.subtract:
bit.bnot will generally return a number larger than 2^31-1, but when it's passed to bit.band it gets rounded down to 2^31-1, and no bits will change.
This results in the color not being subtracted
I'm assuming the api was changed up for the eventual migration towards Lua 5.2, but numbers should wrap around instead or being range limited
EDIT: I guess this is more Java's fault instead of ComputerCraft's fault, casting a double directly to an int will range limit it, but intermediately casting it to a long and then to an int gets the correct wrapped result.
All functions will limit the number to the range of a signed 32bit number, but give numbers that are unsigned 32bit numbers.
And by limit to a range, it'll do something more like
math.min(math.max(number, -2^31), 2^31-1)
instead of wrapping aroundThis will for example, break colors.subtract:
bit.bnot will generally return a number larger than 2^31-1, but when it's passed to bit.band it gets rounded down to 2^31-1, and no bits will change.
This results in the color not being subtracted
I'm assuming the api was changed up for the eventual migration towards Lua 5.2, but numbers should wrap around instead or being range limited
EDIT: I guess this is more Java's fault instead of ComputerCraft's fault, casting a double directly to an int will range limit it, but intermediately casting it to a long and then to an int gets the correct wrapped result.
Edited on 21 July 2015 - 04:54 PM