X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=tests%2Fxor.qc;h=41d02e95ee366a80a48fdb96975ed55d9a9d9267;hb=6de7c45618c6d57b64583a15c1eac705dac92ba8;hp=81fb1149e5c4c94762f7ddb3ef7e0f9c12773a71;hpb=a8fddbb7d33d5a5627c6d866c8150b6d3c73bc2b;p=xonotic%2Fgmqcc.git diff --git a/tests/xor.qc b/tests/xor.qc index 81fb114..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; @@ -9,4 +22,31 @@ void main() { print(ftos(z), "\n"); print(ftos(c), "\n"); + + // commutative? + if (x ^ y == y ^ x) + print("commutative\n"); + + // assocative? + if (x ^ (y ^ z) == (x ^ y) ^ z) + print("assocative\n"); + + // elements are their own inverse? + if (x ^ 0 == x) + print("inverse\n"); + + // vector ^ vector + // vector ^ float + // are legal in constant expressions (currently) + const vector v3 = '5 2 5' ^ '3 10 3'; + const vector v4 = '5 2 5' ^ 10; + + 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"); }