mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
Merge pull request #2010 from Fingercomp/bit32-rotate-fix
Fix bit32.lrotate and bit32.rrotate
This commit is contained in:
commit
ee620aeacd
@ -66,9 +66,15 @@ function bit32.replace(n, v, field, width)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function bit32.lrotate(x, disp)
|
function bit32.lrotate(x, disp)
|
||||||
if disp == 0 then return x
|
if disp == 0 then
|
||||||
elseif disp < 0 then return bit32.rrotate(x, -disp)
|
return x
|
||||||
else return trim((x << disp) | (x >> (32 - disp))) end
|
elseif disp < 0 then
|
||||||
|
return bit32.rrotate(x, -disp)
|
||||||
|
else
|
||||||
|
disp = disp & 31
|
||||||
|
x = trim(x)
|
||||||
|
return trim((x << disp) | (x >> (32 - disp)))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function bit32.lshift(x, disp)
|
function bit32.lshift(x, disp)
|
||||||
@ -76,9 +82,15 @@ function bit32.lshift(x, disp)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function bit32.rrotate(x, disp)
|
function bit32.rrotate(x, disp)
|
||||||
if disp == 0 then return x
|
if disp == 0 then
|
||||||
elseif disp < 0 then return bit32.lrotate(x, -disp)
|
return x
|
||||||
else return trim((x >> disp) | (x << (32 - disp))) end
|
elseif disp < 0 then
|
||||||
|
return bit32.lrotate(x, -disp)
|
||||||
|
else
|
||||||
|
disp = disp & 31
|
||||||
|
x = trim(x)
|
||||||
|
return trim((x >> disp) | (x << (32 - disp)))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function bit32.rshift(x, disp)
|
function bit32.rshift(x, disp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user