summaryrefslogtreecommitdiffstats
path: root/dimension/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-03-20 15:55:52 -0400
committerTavian Barnes <tavianator@gmail.com>2010-03-20 15:55:52 -0400
commitac3e97014885af00b5a2eb01df232221482db023 (patch)
tree39163e9eed2427580260d0097b1c7887bcc536a5 /dimension/parse.c
parent5da32d0dce6b8ade0b636b83f67b6244e6a56494 (diff)
downloaddimension-ac3e97014885af00b5a2eb01df232221482db023.tar.xz
Support max() and min().
Diffstat (limited to 'dimension/parse.c')
-rw-r--r--dimension/parse.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/dimension/parse.c b/dimension/parse.c
index fb9de1c..177a96c 100644
--- a/dimension/parse.c
+++ b/dimension/parse.c
@@ -1184,6 +1184,12 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
case DMNSN_AST_INT_DIV:
dmnsn_make_ast_integer(&ret, l/r);
break;
+ case DMNSN_AST_MAX:
+ dmnsn_make_ast_integer(&ret, l > r ? l : r);
+ break;
+ case DMNSN_AST_MIN:
+ dmnsn_make_ast_integer(&ret, l < r ? l : r);
+ break;
case DMNSN_AST_MOD:
dmnsn_make_ast_float(&ret, fmod(l, r));
break;
@@ -1287,6 +1293,36 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
case DMNSN_AST_INT_DIV:
dmnsn_make_ast_float(&ret, trunc(l/r));
break;
+ case DMNSN_AST_MAX:
+ if (l > r) {
+ if (lhs.type == DMNSN_AST_INTEGER) {
+ dmnsn_make_ast_maybe_integer(&ret, l);
+ } else {
+ dmnsn_make_ast_float(&ret, l);
+ }
+ } else {
+ if (rhs.type == DMNSN_AST_INTEGER) {
+ dmnsn_make_ast_maybe_integer(&ret, r);
+ } else {
+ dmnsn_make_ast_float(&ret, r);
+ }
+ }
+ break;
+ case DMNSN_AST_MIN:
+ if (l < r) {
+ if (lhs.type == DMNSN_AST_INTEGER) {
+ dmnsn_make_ast_maybe_integer(&ret, l);
+ } else {
+ dmnsn_make_ast_float(&ret, l);
+ }
+ } else {
+ if (rhs.type == DMNSN_AST_INTEGER) {
+ dmnsn_make_ast_maybe_integer(&ret, r);
+ } else {
+ dmnsn_make_ast_float(&ret, r);
+ }
+ }
+ break;
case DMNSN_AST_MOD:
dmnsn_make_ast_float(&ret, fmod(l, r));
break;
@@ -1395,6 +1431,8 @@ dmnsn_eval(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
case DMNSN_AST_OR:
case DMNSN_AST_ATAN2:
case DMNSN_AST_INT_DIV:
+ case DMNSN_AST_MAX:
+ case DMNSN_AST_MIN:
case DMNSN_AST_MOD:
case DMNSN_AST_POW:
case DMNSN_AST_STRCMP: