Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Version with some breathing room...
proc s(x, y, b: var int)=
x = x div 2
y = y div 2
b *= 2
proc n(x: var int): int =
return -(x+1)
proc a(x, y: var int): int =
var b = 1
while x > 0 and y > 0:
if (x mod 2 + y mod 2) == 2:
result += b
s(x,y,b)
proc o(x, y: var int): int =
var b = 1
while x + y > 0:
if (x mod 2 + y mod 2) >= 1:
result += b
s(x,y,b)
proc r(x, y: var int): int =
var b = 1
while x + y > 0:
if (x mod 2 + y mod 2) == 1:
result += b
s(x,y,b)
# Test harness
proc test(i,j, exp: int; p: proc; op: string){.procvar.}=
var
act: int
var x = i
var y = j
act = p(x,y)
if(exp != act):
echo("Error! ", i, op, j," ", exp," ", act)
import threadpool
var
x, exp, act: int
for i in countup(0, 0xffffffff):
x = i
exp = not x
act = n(x)
if(exp != act):
echo("Error! ~", i)
parallel:
for j in countup(0,0xffffffff):
spawn test(i,j,i and j, a," & ")
spawn test(i,j,i or j, o," | ")
spawn test(i,j,i xor j, r," ^ ")
@corytodd

This comment has been minimized.

Copy link
Owner Author

@corytodd corytodd commented Apr 3, 2015

Added test harness

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment