From: Dale Weiler Date: Sun, 16 Jun 2013 02:24:10 +0000 (+0000) Subject: Add the good old xor swap trick to the xor test, yes it works :P X-Git-Tag: v0.3.0~121 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5d2b57394efd1eb641403efb540411ed5d087124;p=xonotic%2Fgmqcc.git Add the good old xor swap trick to the xor test, yes it works :P --- diff --git a/tests/xor.qc b/tests/xor.qc index b2820ef..41d02e9 100644 --- a/tests/xor.qc +++ b/tests/xor.qc @@ -1,3 +1,16 @@ +vector swap(float x, float y) { + vector ret = '0 0 0'; + // everyone knows this trick + ret.x = x; + ret.y = y; + + ret.x = ret.x ^ ret.y; + ret.y = ret.y ^ ret.x; + ret.x = ret.x ^ ret.y; + + return ret; +} + void main() { float x = 5; float y = 3; @@ -30,4 +43,10 @@ void main() { print("vv: ", vtos(v3), "\n"); print("vf: ", vtos(v4), "\n"); + + // good olde xor swap test too + float swap_x = 100; + float swap_y = 200; + vector swaps = swap(swap_x, swap_y); + print("100:200 swapped is: ", ftos(swaps.x), ":", ftos(swaps.y), "\n"); } diff --git a/tests/xor.tmpl b/tests/xor.tmpl index a2a4efc..5394f3d 100644 --- a/tests/xor.tmpl +++ b/tests/xor.tmpl @@ -10,3 +10,4 @@ M: assocative M: inverse M: vv: '6 8 6' M: vf: '15 8 15' +M: 100:200 swapped is: 200:100