]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - tests/xor.qc
Merge branch 'divVerent/ftypeless-stores' of git://git.xonotic.org/xonotic/gmqcc...
[xonotic/gmqcc.git] / tests / xor.qc
index 2006944ef1f0b37a1c87a5cf45e98a4092ee1a42..531a5fb42be3427daa939816274a14658e12089b 100644 (file)
@@ -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;
@@ -21,4 +34,33 @@ void main() {
     // elements are their own inverse?
     if (x ^ 0 == x)
         print("inverse\n");
+        
+    // vector ^ vector
+    // vector ^ float
+    // are legal in constant expressions (currently)
+    vector v1 = '5 2 5';
+    vector v2 = '3 10 3';
+
+    print("vv: ", vtos(v1 ^ v2), "\n");
+    print("vf: ", vtos(v1 ^ 10), "\n");
+    
+    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");
+
+    // good olde xor swap test too
+    vector swap_u = '1 2 3';
+    vector swap_v = '4 5 6';
+    swap_u ^= swap_v;
+    swap_v ^= swap_u;
+    swap_u ^= swap_v;
+    print("'1 2 3':'4 5 6' swapped is: ", vtos(swap_u), ":", vtos(swap_v), "\n");
 }