]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - fold.c
folder: change ~ for floats too
[xonotic/gmqcc.git] / fold.c
diff --git a/fold.c b/fold.c
index 735758cb688c8fe48feee99980996547bf40e696..c75106ad74c472b8265e4f532a9e48257566e28b 100644 (file)
--- a/fold.c
+++ b/fold.c
@@ -123,9 +123,9 @@ static GMQCC_INLINE vec3_t vec3_xorvf(vec3_t a, qcfloat_t b) {
 
 static GMQCC_INLINE vec3_t vec3_not(vec3_t a) {
     vec3_t out;
-    out.x = (qcfloat_t)(~((qcint_t)a.x));
-    out.y = (qcfloat_t)(~((qcint_t)a.y));
-    out.z = (qcfloat_t)(~((qcint_t)a.z));
+    out.x = -1-a.x;
+    out.y = -1-a.y;
+    out.z = -1-a.z;
     return out;
 }
 
@@ -160,7 +160,7 @@ static GMQCC_INLINE qcfloat_t vec3_notf(vec3_t a) {
 }
 
 static GMQCC_INLINE bool vec3_pbool(vec3_t a) {
-    return (a.x && a.y && a.z);
+    return (a.x || a.y || a.z);
 }
 
 static GMQCC_INLINE vec3_t vec3_cross(vec3_t a, vec3_t b) {
@@ -537,11 +537,10 @@ static GMQCC_INLINE ast_expression *fold_op_xor(fold_t *fold, ast_value *a, ast_
         if (fold_can_2(a, b))
             return fold_constgen_float(fold, (qcfloat_t)(((qcint_t)fold_immvalue_float(a)) ^ ((qcint_t)fold_immvalue_float(b))));
     } else {
-        if (isvector(b)) {
-            if (fold_can_2(a, b))
+        if (fold_can_2(a, b)) {
+            if (isvector(b))
                 return fold_constgen_vector(fold, vec3_xor(fold_immvalue_vector(a), fold_immvalue_vector(b)));
-        } else {
-            if (fold_can_2(a, b))
+            else
                 return fold_constgen_vector(fold, vec3_xorvf(fold_immvalue_vector(a), fold_immvalue_float(b)));
         }
     }
@@ -606,11 +605,10 @@ static GMQCC_INLINE ast_expression *fold_op_lteqgt(fold_t *fold, ast_value *a, a
 
 static GMQCC_INLINE ast_expression *fold_op_cmp(fold_t *fold, ast_value *a, ast_value *b, bool ne) {
     if (fold_can_2(a, b)) {
-        return fold_constgen_float(
-                    fold,
-                    (ne) ? (fold_immvalue_float(a) != fold_immvalue_float(b))
-                         : (fold_immvalue_float(a) == fold_immvalue_float(b))
-                );
+        if (isfloat(a) && isfloat(b))
+            return fold_constgen_float(fold, ne != (fold_immvalue_float(a) == fold_immvalue_float(b)));
+        if (isvector(a) && isvector(b))
+            return fold_constgen_float(fold, ne != vec3_cmp(fold_immvalue_vector(a), fold_immvalue_vector(b)));
     }
     return NULL;
 }
@@ -618,7 +616,7 @@ static GMQCC_INLINE ast_expression *fold_op_cmp(fold_t *fold, ast_value *a, ast_
 static GMQCC_INLINE ast_expression *fold_op_bnot(fold_t *fold, ast_value *a) {
     if (isfloat(a)) {
         if (fold_can_1(a))
-            return fold_constgen_float(fold, ~((qcint_t)fold_immvalue_float(a)));
+            return fold_constgen_float(fold, -1-fold_immvalue_float(a));
     } else {
         if (isvector(a)) {
             if (fold_can_1(a))