@@ -136,7 +136,7 @@ LICENSE
136
136
137
137
--]]
138
138
139
- local M = {_TYPE = ' module' , _NAME = ' bit.numberlua' , _VERSION = ' 000.003.2011-11-28 ' }
139
+ local M = {_TYPE = ' module' , _NAME = ' bit.numberlua' , _VERSION = ' 000.003.2011-11-29 ' }
140
140
141
141
local floor = math.floor
142
142
@@ -177,39 +177,37 @@ local function make_bitop(t)
177
177
end
178
178
179
179
-- ok? probably not if running on a 32-bit int Lua number type platform
180
- local function tobit (x )
180
+ function M . tobit (x )
181
181
return x % 2 ^ 32
182
182
end
183
- M .tobit = tobit
184
183
185
- local bxor = make_bitop {[0 ]= {[0 ]= 0 ,[1 ]= 1 },[1 ]= {[0 ]= 1 ,[1 ]= 0 }, n = 4 }
186
- M . bxor = bxor
184
+ M . bxor = make_bitop {[0 ]= {[0 ]= 0 ,[1 ]= 1 },[1 ]= {[0 ]= 1 ,[1 ]= 0 }, n = 4 }
185
+ local bxor = M . bxor
187
186
188
187
local F8 = 2 ^ 32 - 1
189
- local function bnot (a ) return F8 - a end
190
- M . bnot = bnot
188
+ function M . bnot (a ) return F8 - a end
189
+ local bnot = M . bnot
191
190
192
- local function band (a ,b ) return ((a + b ) - bxor (a ,b ))/ 2 end
193
- M . band = band
191
+ function M . band (a ,b ) return ((a + b ) - bxor (a ,b ))/ 2 end
192
+ local band = M . band
194
193
195
- local function bor (a ,b ) return F8 - band (F8 - a , F8 - b ) end
196
- M .bor = bor
194
+ function M .bor (a ,b ) return F8 - band (F8 - a , F8 - b ) end
197
195
198
196
local lshift , rshift -- forward declare
199
197
200
- function rshift (a ,disp ) -- Lua5.2 style
198
+ function M . rshift (a ,disp ) -- Lua5.2 style
201
199
if disp < 0 then return lshift (a ,- disp ) end
202
200
return floor (a % 2 ^ 32 / 2 ^ disp )
203
201
end
204
- M . rshift = rshift
202
+ rshift = M . rshift
205
203
206
- function lshift (a ,disp ) -- Lua5.2 style
204
+ function M . lshift (a ,disp ) -- Lua5.2 style
207
205
if disp < 0 then return rshift (a ,- disp ) end
208
206
return (a * 2 ^ disp ) % 2 ^ 32
209
207
end
210
- M . lshift = lshift
208
+ lshift = M . lshift
211
209
212
- local function tohex (x , n ) -- BitOp style
210
+ function M . tohex (x , n ) -- BitOp style
213
211
n = n or 8
214
212
local up
215
213
if n < 0 then
@@ -219,43 +217,38 @@ local function tohex(x, n) -- BitOp style
219
217
x = band (x , 16 ^ n - 1 )
220
218
return (' %0' .. n .. (up and ' X' or ' x' )):format (x )
221
219
end
222
- M .tohex = tohex
223
220
224
- local function extract (n , field , width ) -- Lua5.2 style
221
+ function M . extract (n , field , width ) -- Lua5.2 style
225
222
width = width or 1
226
223
return band (rshift (n , field ), 2 ^ width - 1 )
227
224
end
228
- M .extract = extract
229
225
230
- local function replace (n , v , field , width ) -- Lua5.2 style
226
+ function M . replace (n , v , field , width ) -- Lua5.2 style
231
227
width = width or 1
232
228
local mask1 = 2 ^ width - 1
233
229
v = band (v , mask1 ) -- required by spec?
234
230
local mask = bnot (lshift (mask1 , field ))
235
231
return band (n , mask ) + lshift (v , field )
236
232
end
237
- M .replace = replace
238
233
239
- local function bswap (x ) -- BitOp style
234
+ function M . bswap (x ) -- BitOp style
240
235
local a = band (x , 0xff ); x = rshift (x , 8 )
241
236
local b = band (x , 0xff ); x = rshift (x , 8 )
242
237
local c = band (x , 0xff ); x = rshift (x , 8 )
243
238
local d = band (x , 0xff )
244
239
return lshift (lshift (lshift (a , 8 ) + b , 8 ) + c , 8 ) + d
245
240
end
246
- M .bswap = bswap
247
241
248
- local function rrotate (x , disp ) -- Lua5.2 style
242
+ function M . rrotate (x , disp ) -- Lua5.2 style
249
243
disp = disp % 32
250
244
local low = band (x , 2 ^ disp - 1 )
251
245
return rshift (x , disp ) + lshift (low , 32 - disp )
252
246
end
253
- M . rrotate = rrotate
247
+ local rrotate = M . rrotate
254
248
255
- local function lrotate (x , disp ) -- Lua5.2 style
249
+ function M . lrotate (x , disp ) -- Lua5.2 style
256
250
return rrotate (x , - disp )
257
251
end
258
- M .lrotate = lrotate
259
252
260
253
M .rol = M .lrotate -- LuaOp style
261
254
M .ror = M .rrotate -- LuaOp style
0 commit comments