mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-30 11:04:17 +00:00
LuaBit: Minor cleanup
Bug: T353678
Change-Id: I19527eb162c20b5a6017dc3c4dd2b98bf5cad5d9
(cherry picked from commit 836baa7142
)
This commit is contained in:
parent
e891a9f025
commit
4b702cbc54
|
@ -133,7 +133,6 @@ local function bit_and(m, n)
|
|||
end
|
||||
|
||||
local function bit_not(n)
|
||||
|
||||
local tbl = to_bits(n)
|
||||
local size = math.max(table.getn(tbl), 32)
|
||||
for i = 1, size do
|
||||
|
@ -213,8 +212,7 @@ end
|
|||
local function bit_xor2(m, n)
|
||||
local rhs = bit_or(bit_not(m), bit_not(n))
|
||||
local lhs = bit_or(m, n)
|
||||
local rslt = bit_and(lhs, rhs)
|
||||
return rslt
|
||||
return bit_and(lhs, rhs)
|
||||
end
|
||||
|
||||
--------------------
|
||||
|
@ -249,16 +247,3 @@ for i = 1, 100 do
|
|||
end
|
||||
end
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -36,11 +36,11 @@ local function to_hex(n)
|
|||
n = bit.tonumb(n)
|
||||
end
|
||||
|
||||
hex_tbl = {'A', 'B', 'C', 'D', 'E', 'F'}
|
||||
hex_str = ""
|
||||
local hex_tbl = {'A', 'B', 'C', 'D', 'E', 'F'}
|
||||
local hex_str = ""
|
||||
|
||||
while(n ~= 0) do
|
||||
last = math.mod(n, 16)
|
||||
local last = math.mod(n, 16)
|
||||
if(last < 10) then
|
||||
hex_str = tostring(last) .. hex_str
|
||||
else
|
||||
|
@ -59,15 +59,13 @@ local function to_dec(hex)
|
|||
error("non-string type passed in.")
|
||||
end
|
||||
|
||||
head = string.sub(hex, 1, 2)
|
||||
local head = string.sub(hex, 1, 2)
|
||||
|
||||
if( head ~= "0x" and head ~= "0X") then
|
||||
error("wrong hex format, should lead by 0x or 0X.")
|
||||
end
|
||||
|
||||
v = tonumber(string.sub(hex, 3), 16)
|
||||
|
||||
return v;
|
||||
return tonumber(string.sub(hex, 3), 16)
|
||||
end
|
||||
|
||||
--------------------
|
||||
|
@ -88,7 +86,6 @@ h = to_hex(d)
|
|||
print(h)
|
||||
print(to_dec(h))
|
||||
|
||||
|
||||
for i = 1, 100000 do
|
||||
h = hex.to_hex(i)
|
||||
d = hex.to_dec(h)
|
||||
|
|
Loading…
Reference in a new issue