[aravis] evaluator: if asking for a double do float division.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] evaluator: if asking for a double do float division.
- Date: Thu, 6 Jan 2011 14:24:36 +0000 (UTC)
commit a99254e44e07efc61b6deebb25c0aec22f8f52e7
Author: Tom Cobb <tom cobb diamond ac uk>
Date: Thu Jan 6 15:22:44 2011 +0100
evaluator: if asking for a double do float division.
If a Converter (but not an IntConverter) element divides two integer values,
the result should be stored as a floating point number according to the Genicam
spec.
src/arvevaluator.c | 5 ++++-
tests/evaluator.c | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/src/arvevaluator.c b/src/arvevaluator.c
index f44517e..2adbd22 100644
--- a/src/arvevaluator.c
+++ b/src/arvevaluator.c
@@ -649,7 +649,10 @@ evaluate (GSList *token_stack, GHashTable *variables, gint64 *v_int64, double *v
break;
case ARV_EVALUATOR_TOKEN_DIVISION:
if (arv_value_holds_double (&stack[index-1]) ||
- arv_value_holds_double (&stack[index])) {
+ 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;
diff --git a/tests/evaluator.c b/tests/evaluator.c
index 6b9e13d..9921d42 100644
--- a/tests/evaluator.c
+++ b/tests/evaluator.c
@@ -21,7 +21,7 @@ static const ExpressionTestData expression_test_data[] = {
{"/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.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},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]