Install a moduli(5) manual page.
[dragonfly.git] / contrib / bsdinstaller-1.1.6 / src / backend / lua / lib / bitwise.lua
1 -- lib/bitwise.lua
2 -- $Id: bitwise.lua,v 1.1 2005/02/22 02:54:32 cpressey Exp $
3 -- Package for (pure-Lua portable but extremely slow) bitwise arithmetic.
4
5 -- BEGIN lib/bitwise.lua --
6
7 --[[---------]]--
8 --[[ Bitwise ]]--
9 --[[---------]]--
10
11 local odd = function(x)
12         return x ~= math.floor(x / 2) * 2
13 end
14
15 Bitwise = {}
16
17 Bitwise.bw_and = function(a, b)
18         local c, pow = 0, 1
19         while a > 0 or b > 0 do
20                 if odd(a) and odd(b) then
21                         c = c + pow
22                 end
23                 a = math.floor(a / 2)
24                 b = math.floor(b / 2)
25                 pow = pow * 2
26         end
27         return c
28 end
29
30 Bitwise.bw_or = function(a, b)
31         local c, pow = 0, 1
32         while a > 0 or b > 0 do
33                 if odd(a) or odd(b) then
34                         c = c + pow
35                 end
36                 a = math.floor(a / 2)
37                 b = math.floor(b / 2)
38                 pow = pow * 2
39         end
40         return c
41 end
42
43 -- END of lib/bitwise.lua --