Debian Codegraph @

lua/include/bitwise.lua

raw symbols SCIP
1 --[[
2 Copyright (C) 2014 HarpyWar ([email protected])
3
4 This file is a part of the PvPGN Project http://pvpgn.pro
5 Licensed under the same terms as Lua itself.
6 ]]--
7
8
9 --
10 -- Bitwise functions:
11 -- math_not, math_and, math_or, math_xor
12 --
13
14 local function nand(x,y,z)
15 z=z or 2^16
16 if z<2 then
17 return 1-x*y
18 else
19 return nand((x-x%z)/z,(y-y%z)/z,math.sqrt(z))*z+nand(x%z,y%z,math.sqrt(z))
20 end
21 end
22 function math_not(y,z)
23 return nand(nand(0,0,z),y,z)
24 end
25 function math_and(x,y,z)
26 return nand(math_not(0,z),nand(x,y,z),z)
27 end
28 function math_or(x,y,z)
29 return nand(math_not(x,z),math_not(y,z),z)
30 end
31 function math_xor(x,y,z)
32 return math_and(nand(x,y,z),math_or(x,y,z),z)
33 end