[aravis] evaluator: don't try to be smart about result type of division
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] evaluator: don't try to be smart about result type of division
- Date: Sat, 17 Jan 2015 15:24:45 +0000 (UTC)
commit 62d5c2d67d2a5ae1b82ee23e987ad7779e09d2c5
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Sat Jan 17 16:22:05 2015 +0100
evaluator: don't try to be smart about result type of division
src/arvevaluator.c | 54 +++++++++++++++++++--------------------------------
tests/evaluator.c | 3 +-
2 files changed, 22 insertions(+), 35 deletions(-)
---
diff --git a/src/arvevaluator.c b/src/arvevaluator.c
index 5f1206c..986f3a4 100644
--- a/src/arvevaluator.c
+++ b/src/arvevaluator.c
@@ -647,51 +647,37 @@ evaluate (GSList *token_stack, GHashTable *variables, gint64 *v_int64, double *v
arv_value_get_int64 (&stack[index]));
break;
case ARV_EVALUATOR_TOKEN_DIVISION:
- if (arv_value_holds_double (&stack[index-1]) ||
- arv_value_holds_double (&stack[index]) ||
- /* Do float division if asked for a float value, even
- * with integer operands. */
- v_double != NULL) {
- if (arv_value_get_double (&stack[index]) == 0.0) {
- status = ARV_EVALUATOR_STATUS_DIVISION_BY_ZERO;
- goto CLEANUP;
- }
- arv_value_set_double (&stack[index-1],
- arv_value_get_double (&stack[index-1]) /
- arv_value_get_double (&stack[index]));
- } else {
- if (arv_value_get_int64 (&stack[index]) == 0) {
- status = ARV_EVALUATOR_STATUS_DIVISION_BY_ZERO;
- goto CLEANUP;
- }
- arv_value_set_int64 (&stack[index-1],
- arv_value_get_int64 (&stack[index-1]) /
- arv_value_get_int64 (&stack[index]));
+ if (arv_value_get_double (&stack[index]) == 0.0) {
+ status = ARV_EVALUATOR_STATUS_DIVISION_BY_ZERO;
+ goto CLEANUP;
}
+ arv_value_set_double (&stack[index-1],
+ arv_value_get_double (&stack[index-1]) /
+ arv_value_get_double (&stack[index]));
break;
case ARV_EVALUATOR_TOKEN_MULTIPLICATION:
if (arv_value_holds_double (&stack[index-1]) ||
arv_value_holds_double (&stack[index]))
arv_value_set_double (&stack[index-1],
- arv_value_get_double (&stack[index-1]) *
- arv_value_get_double (&stack[index]));
+ arv_value_get_double (&stack[index-1]) *
+ arv_value_get_double (&stack[index]));
else
arv_value_set_int64 (&stack[index-1],
- arv_value_get_int64 (&stack[index-1]) *
- arv_value_get_int64 (&stack[index]));
+ arv_value_get_int64 (&stack[index-1]) *
+ arv_value_get_int64 (&stack[index]));
break;
case ARV_EVALUATOR_TOKEN_POWER:
arv_value_set_double (&stack[index-1],
- pow (arv_value_get_double(&stack[index-1]),
- arv_value_get_double(&stack[index])));
+ pow (arv_value_get_double(&stack[index-1]),
+ arv_value_get_double(&stack[index])));
break;
case ARV_EVALUATOR_TOKEN_MINUS:
if (arv_value_holds_double (&stack[index]))
arv_value_set_double (&stack[index],
- -arv_value_get_double (&stack[index]));
+ -arv_value_get_double (&stack[index]));
else
arv_value_set_int64 (&stack[index],
- -arv_value_get_int64 (&stack[index]));
+ -arv_value_get_int64 (&stack[index]));
break;
case ARV_EVALUATOR_TOKEN_PLUS:
break;
@@ -723,10 +709,10 @@ evaluate (GSList *token_stack, GHashTable *variables, gint64 *v_int64, double *v
case ARV_EVALUATOR_TOKEN_FUNCTION_NEG:
if (arv_value_holds_double (&stack[index]))
arv_value_set_double (&stack[index],
- -arv_value_get_double (&stack[index-1]));
+ -arv_value_get_double (&stack[index-1]));
else
arv_value_set_int64 (&stack[index],
- -arv_value_get_int64 (&stack[index]));
+ -arv_value_get_int64 (&stack[index]));
break;
case ARV_EVALUATOR_TOKEN_FUNCTION_ATAN:
arv_value_set_double (&stack[index], atan (arv_value_get_double
(&stack[index])));
@@ -737,10 +723,10 @@ evaluate (GSList *token_stack, GHashTable *variables, gint64 *v_int64, double *v
case ARV_EVALUATOR_TOKEN_FUNCTION_ABS:
if (arv_value_holds_double (&stack[index]))
arv_value_set_double (&stack[index],
- fabs (arv_value_get_double (&stack[index-1])));
+ fabs (arv_value_get_double (&stack[index-1])));
else
arv_value_set_int64 (&stack[index],
- abs (arv_value_get_int64 (&stack[index])));
+ abs (arv_value_get_int64 (&stack[index])));
break;
case ARV_EVALUATOR_TOKEN_FUNCTION_EXP:
arv_value_set_double (&stack[index], exp (arv_value_get_double
(&stack[index])));
@@ -757,10 +743,10 @@ evaluate (GSList *token_stack, GHashTable *variables, gint64 *v_int64, double *v
case ARV_EVALUATOR_TOKEN_FUNCTION_TRUNC:
if (arv_value_get_double (&stack[index]) > 0.0)
arv_value_set_double (&stack[index],
- floor (arv_value_get_double (&stack[index])));
+ floor (arv_value_get_double (&stack[index])));
else
arv_value_set_double (&stack[index],
- ceil (arv_value_get_double (&stack[index])));
+ ceil (arv_value_get_double (&stack[index])));
break;
case ARV_EVALUATOR_TOKEN_FUNCTION_FLOOR:
arv_value_set_double (&stack[index], floor (arv_value_get_double
(&stack[index])));
diff --git a/tests/evaluator.c b/tests/evaluator.c
index 14c6a53..da83d55 100644
--- a/tests/evaluator.c
+++ b/tests/evaluator.c
@@ -64,7 +64,8 @@ static const ExpressionTestData expression_test_data[] = {
{"/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/bugs/681048-remaining-op", "(0 & 1)=0?((0 & 1)+2):1", 2, 2.0},
+ {"/evaluator/bugs/743025-division-by-zero", "(4/(20/10000))", 2000, 2000.0}
};
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]