summaryrefslogtreecommitdiffstats
path: root/dimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-03-19 13:38:22 -0400
committerTavian Barnes <tavianator@gmail.com>2010-03-19 13:38:22 -0400
commitfc06cb624d79788923ab2dedb3cd2ccab53cb2b4 (patch)
tree081c1267b2661b53dfcb02b636c6594e05c6e195 /dimension
parentc01e193e19d45e2c5b1e86928cedc11cdbdda476 (diff)
downloaddimension-fc06cb624d79788923ab2dedb3cd2ccab53cb2b4.tar.xz
Make float equality comparisons more relaxed.
Diffstat (limited to 'dimension')
-rw-r--r--dimension/parse.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/dimension/parse.c b/dimension/parse.c
index 7edf22a..7b4a35b 100644
--- a/dimension/parse.c
+++ b/dimension/parse.c
@@ -903,6 +903,7 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_make_ast_float(&ret, ((double)l)/r);
}
break;
+
case DMNSN_AST_EQUAL:
dmnsn_make_ast_integer(&ret, l == r);
break;
@@ -989,11 +990,12 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
case DMNSN_AST_DIV:
dmnsn_make_ast_float(&ret, l/r);
break;
+
case DMNSN_AST_EQUAL:
- dmnsn_make_ast_integer(&ret, l == r);
+ dmnsn_make_ast_integer(&ret, fabs(l - r) < dmnsn_epsilon);
break;
case DMNSN_AST_NOT_EQUAL:
- dmnsn_make_ast_integer(&ret, l != r);
+ dmnsn_make_ast_integer(&ret, fabs(l - r) >= dmnsn_epsilon);
break;
case DMNSN_AST_LESS:
dmnsn_make_ast_integer(&ret, l < r);
@@ -1008,10 +1010,12 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_make_ast_integer(&ret, l >= r);
break;
case DMNSN_AST_AND:
- dmnsn_make_ast_integer(&ret, l && r);
+ dmnsn_make_ast_integer(&ret, fabs(l) >= dmnsn_epsilon
+ && fabs(r) >= dmnsn_epsilon);
break;
case DMNSN_AST_OR:
- dmnsn_make_ast_integer(&ret, l || r);
+ dmnsn_make_ast_integer(&ret, fabs(l) >= dmnsn_epsilon
+ || fabs(r) >= dmnsn_epsilon);
break;
default: