[aravis] evaluator: fix comparisons when one of the operand is a double.



commit cce7ef8b4ea7857a78817684a196ccb68241af2b
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Sat Dec 21 23:29:54 2013 +0100

    evaluator: fix comparisons when one of the operand is a double.
    
    fixes https://bugzilla.gnome.org/show_bug.cgi?id=720809.

 src/arvevaluator.c |   12 +++---
 tests/evaluator.c  |   98 +++++++++++++++++++++++++++++-----------------------
 2 files changed, 61 insertions(+), 49 deletions(-)
---
diff --git a/src/arvevaluator.c b/src/arvevaluator.c
index e042014..7728a60 100644
--- a/src/arvevaluator.c
+++ b/src/arvevaluator.c
@@ -540,7 +540,7 @@ evaluate (GSList *token_stack, GHashTable *variables, gint64 *v_int64, double *v
                                                      arv_value_get_int64 (&stack[index]));
                                break;
                        case ARV_EVALUATOR_TOKEN_EQUAL:
-                               if (arv_value_holds_int64 (&stack[index-1]) ||
+                               if (arv_value_holds_int64 (&stack[index-1]) &&
                                    arv_value_holds_int64 (&stack[index]))
                                        arv_value_set_int64 (&stack[index-1],
                                                              arv_value_get_int64 (&stack[index-1]) ==
@@ -551,7 +551,7 @@ evaluate (GSList *token_stack, GHashTable *variables, gint64 *v_int64, double *v
                                                              arv_value_get_double (&stack[index]));
                                break;
                        case ARV_EVALUATOR_TOKEN_NOT_EQUAL:
-                               if (arv_value_holds_int64 (&stack[index-1]) ||
+                               if (arv_value_holds_int64 (&stack[index-1]) &&
                                    arv_value_holds_int64 (&stack[index]))
                                        arv_value_set_int64 (&stack[index-1],
                                                              arv_value_get_int64 (&stack[index-1]) !=
@@ -562,7 +562,7 @@ evaluate (GSList *token_stack, GHashTable *variables, gint64 *v_int64, double *v
                                                              arv_value_get_double (&stack[index]));
                                break;
                        case ARV_EVALUATOR_TOKEN_LESS_OR_EQUAL:
-                               if (arv_value_holds_int64 (&stack[index-1]) ||
+                               if (arv_value_holds_int64 (&stack[index-1]) &&
                                    arv_value_holds_int64 (&stack[index]))
                                        arv_value_set_int64 (&stack[index-1],
                                                              arv_value_get_int64 (&stack[index-1]) <=
@@ -573,7 +573,7 @@ evaluate (GSList *token_stack, GHashTable *variables, gint64 *v_int64, double *v
                                                              arv_value_get_double (&stack[index]));
                                break;
                        case ARV_EVALUATOR_TOKEN_GREATER_OR_EQUAL:
-                               if (arv_value_holds_int64 (&stack[index-1]) ||
+                               if (arv_value_holds_int64 (&stack[index-1]) &&
                                    arv_value_holds_int64 (&stack[index]))
                                        arv_value_set_int64 (&stack[index-1],
                                                              arv_value_get_int64 (&stack[index-1]) >=
@@ -584,7 +584,7 @@ evaluate (GSList *token_stack, GHashTable *variables, gint64 *v_int64, double *v
                                                              arv_value_get_double (&stack[index]));
                                break;
                        case ARV_EVALUATOR_TOKEN_LESS:
-                               if (arv_value_holds_int64 (&stack[index-1]) ||
+                               if (arv_value_holds_int64 (&stack[index-1]) &&
                                    arv_value_holds_int64 (&stack[index]))
                                        arv_value_set_int64 (&stack[index-1],
                                                              arv_value_get_int64 (&stack[index-1]) <
@@ -595,7 +595,7 @@ evaluate (GSList *token_stack, GHashTable *variables, gint64 *v_int64, double *v
                                                              arv_value_get_double (&stack[index]));
                                break;
                        case ARV_EVALUATOR_TOKEN_GREATER:
-                               if (arv_value_holds_int64 (&stack[index-1]) ||
+                               if (arv_value_holds_int64 (&stack[index-1]) &&
                                    arv_value_holds_int64 (&stack[index]))
                                        arv_value_set_int64 (&stack[index-1],
                                                              arv_value_get_int64 (&stack[index-1]) >
diff --git a/tests/evaluator.c b/tests/evaluator.c
index 100a555..ee3d2e7 100644
--- a/tests/evaluator.c
+++ b/tests/evaluator.c
@@ -9,50 +9,62 @@ typedef struct {
 } ExpressionTestData;
 
 static const ExpressionTestData expression_test_data[] = {
-       {"/evaluator/addition",         "10+2",                 12,     12.0},
-       {"/evaluator/parentheses",      "(24+2)*2",             52,     52.0},
-       {"/evaluator/precedence",       "24+2*8",               40,     40.0},
-       {"/evaluator/sin",              "sin(PI/2.0)",          1,      1.0},
-       {"/evaluator/ternary-true",     "1=1?1:0",              1,      1.0},
-       {"/evaluator/ternary-false",    "1=0?1:0",              0,      0.0},
-       {"/evaluator/greater-true",     "2>1",                  1,      1.0},
-       {"/evaluator/greater-false",    "2>2",                  0,      0.0},
-       {"/evaluator/lower-true",       "1<2",                  1,      1.0},
-       {"/evaluator/lower-false",      "2<2",                  0,      0.0},
-       {"/evaluator/substraction",     "10-8",                 2,      2.0},
-       {"/evaluator/multiplication",   "2.5*4",                10,     10.0},
-       {"/evaluator/division",         "10/4",                 2,      2.5},
-       {"/evaluator/division-float",   "10.0/4",               2,      2.5},
-       {"/evaluator/minus",            "4*-3",                 -12,    -12.0},
-       {"/evaluator/remainder",        "10%3",                 1,      1.0},
-       {"/evaluator/power",            "2**10",                1024,   1024.0},
-       {"/evaluator/power-precedence", "2**10*2",              2048,   2048.0},
-       {"/evaluator/and",              "255 & 8",              8,      8.0},
-       {"/evaluator/or",               "128 | 8",              136,    136.0},
-       {"/evaluator/xor",              "3 ^ 1",                2,      2.0},
-       {"/evaluator/not",              "~255",                 -256,   -256.0},
-       {"/evaluator/not-equal-true",   "1<>2",                 1,      1.0},
-       {"/evaluator/not-equal-false",  "1<>1",                 0,      0.0},
-       {"/evaluator/equal-true",       "1=1",                  1,      1.0},
-       {"/evaluator/equal-flase",      "1=2",                  0,      0.0},
-       {"/evaluator/greater-true",     "2>1",                  1,      1.0},
-       {"/evaluator/greater-false",    "1>1",                  0,      0.0},
-       {"/evaluator/less-true",        "1<2",                  1,      1.0},
-       {"/evaluator/less-false",       "1<1",                  0,      0.0},
-       {"/evaluator/greater-or-equal-true",    "2>=2",         1,      1.0},
-       {"/evaluator/greater-or-equal-false",   "1>=2",         0,      0.0},
-       {"/evaluator/less-or-equal-true",       "2<=2",         1,      1.0},
-       {"/evaluator/less-or-equal-false",      "2<=1",         0,      0.0},
-       {"/evaluator/logical-and-true", "(2=2)&(1=1)",          1,      1.0},
-       {"/evaluator/logical-and-false","(2=2)&(1=2)",          0,      0.0},
-       {"/evaluator/logical-or-true",  "(2=2)|(1=2)",          1,      1.0},
-       {"/evaluator/logical-or-false", "(1=2)|(0=2)",          0,      0.0},
-       {"/evaluator/left-shift",       "1<<4",                 16,     16.0},
-       {"/evaluator/right-shift",      "16>>4",                1,      1.0},
-       {"/evaluator/cos",              "COS(PI)",              -1,     -1.0},
-       {"/evaluator/sin",              "SIN(-PI/2)",           -1,     -1.0},
-
-       {"/evaluator/bugs/remaining-op",        "(0 & 1)=0?((0 & 1)+2):1",      2, 2.0}
+       {"/evaluator/addition",                         "10+2",                 12,     12.0},
+       {"/evaluator/parentheses",                      "(24+2)*2",             52,     52.0},
+       {"/evaluator/precedence",                       "24+2*8",               40,     40.0},
+       {"/evaluator/sin",                              "sin(PI/2.0)",          1,      1.0},
+       {"/evaluator/ternary-true",                     "1=1?1:0",              1,      1.0},
+       {"/evaluator/ternary-false",                    "1=0?1:0",              0,      0.0},
+       {"/evaluator/greater-true",                     "2>1",                  1,      1.0},
+       {"/evaluator/greater-false",                    "2>2",                  0,      0.0},
+       {"/evaluator/lower-true",                       "1<2",                  1,      1.0},
+       {"/evaluator/lower-false",                      "2<2",                  0,      0.0},
+       {"/evaluator/substraction",                     "10-8",                 2,      2.0},
+       {"/evaluator/multiplication",                   "2.5*4",                10,     10.0},
+       {"/evaluator/division",                         "10/4",                 2,      2.5},
+       {"/evaluator/division-float",                   "10.0/4",               2,      2.5},
+       {"/evaluator/minus",                            "4*-3",                 -12,    -12.0},
+       {"/evaluator/remainder",                        "10%3",                 1,      1.0},
+       {"/evaluator/power",                            "2**10",                1024,   1024.0},
+       {"/evaluator/power-precedence",                 "2**10*2",              2048,   2048.0},
+       {"/evaluator/and",                              "255 & 8",              8,      8.0},
+       {"/evaluator/or",                               "128 | 8",              136,    136.0},
+       {"/evaluator/xor",                              "3 ^ 1",                2,      2.0},
+       {"/evaluator/not",                              "~255",                 -256,   -256.0},
+       {"/evaluator/not-equal-true",                   "1<>2",                 1,      1.0},
+       {"/evaluator/not-equal-false",                  "1<>1",                 0,      0.0},
+       {"/evaluator/equal-true",                       "1=1",                  1,      1.0},
+       {"/evaluator/equal-false",                      "1=2",                  0,      0.0},
+       {"/evaluator/greater-true",                     "2>1",                  1,      1.0},
+       {"/evaluator/greater-false",                    "1>1",                  0,      0.0},
+       {"/evaluator/less-true",                        "1<2",                  1,      1.0},
+       {"/evaluator/less-false",                       "1<1",                  0,      0.0},
+       {"/evaluator/greater-or-equal-true",            "2>=2",                 1,      1.0},
+       {"/evaluator/greater-or-equal-false",           "1>=2",                 0,      0.0},
+       {"/evaluator/less-or-equal-true",               "2<=2",                 1,      1.0},
+       {"/evaluator/less-or-equal-false",              "2<=1",                 0,      0.0},
+       {"/evaluator/not-equal-true-double",            "2.1<>2",               1,      1.0},
+       {"/evaluator/not-equal-false-double",           "1.0<>1",               0,      0.0},
+       {"/evaluator/equal-true-double",                "1.0=1",                1,      1.0},
+       {"/evaluator/equal-false-double",               "2.1=2",                0,      0.0},
+       {"/evaluator/greater-true-double",              "2.1>2",                1,      1.0},
+       {"/evaluator/greater-false-double",             "2>2.1",                0,      0.0},
+       {"/evaluator/less-true-double",                 "2<2.1",                1,      1.0},
+       {"/evaluator/less-false-double",                "2.1<2",                0,      0.0},
+       {"/evaluator/greater-or-equal-true-double",     "2.1>=2",               1,      1.0},
+       {"/evaluator/greater-or-equal-false-double",    "2>=2.1",               0,      0.0},
+       {"/evaluator/less-or-equal-true-double",        "2<=2.1",               1,      1.0},
+       {"/evaluator/less-or-equal-false-double",       "2.1<=2",               0,      0.0},
+       {"/evaluator/logical-and-true",                 "(2=2)&(1=1)",          1,      1.0},
+       {"/evaluator/logical-and-false",                "(2=2)&(1=2)",          0,      0.0},
+       {"/evaluator/logical-or-true",                  "(2=2)|(1=2)",          1,      1.0},
+       {"/evaluator/logical-or-false",                 "(1=2)|(0=2)",          0,      0.0},
+       {"/evaluator/left-shift",                       "1<<4",                 16,     16.0},
+       {"/evaluator/right-shift",                      "16>>4",                1,      1.0},
+       {"/evaluator/cos",                              "COS(PI)",              -1,     -1.0},
+       {"/evaluator/sin",                              "SIN(-PI/2)",           -1,     -1.0},
+
+       {"/evaluator/bugs/remaining-op",                "(0 & 1)=0?((0 & 1)+2):1",      2, 2.0}
 };
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]