// ----------------------------------------------------------------------------
// evaluation of expressions
-static inline calculated_number eval_check_number(calculated_number n, int *error) {
- if(unlikely(isnan(n))) {
- *error = EVAL_ERROR_VALUE_IS_NAN;
- return 0;
- }
-
- if(unlikely(isinf(n))) {
- *error = EVAL_ERROR_VALUE_IS_INFINITE;
- return 0;
- }
-
- return n;
-}
-
static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABLE *v, int *error) {
static uint32_t this_hash = 0, now_hash = 0, after_hash = 0, before_hash = 0, status_hash = 0, removed_hash = 0, uninitialized_hash = 0, undefined_hash = 0, clear_hash = 0, warning_hash = 0, critical_hash = 0;
calculated_number n;
}
*error = EVAL_ERROR_UNKNOWN_VARIABLE;
- buffer_sprintf(exp->error_msg, "unknown variable '%s'", v->name);
+ buffer_sprintf(exp->error_msg, "[ undefined variable '%s' ] ", v->name);
return 0;
}
break;
}
- // return eval_check_number(n, error);
return n;
}
calculated_number n = operators[op->operator].eval(exp, op, error);
- // return eval_check_number(n, error);
return n;
}
buffer_reset(exp->error_msg);
exp->result = eval_node(exp, (EVAL_NODE *)exp->nodes, &exp->error);
- if(exp->error == EVAL_ERROR_OK)
- exp->result = eval_check_number(exp->result, &exp->error);
+ if(unlikely(isnan(exp->result))) {
+ if(exp->error == EVAL_ERROR_OK)
+ exp->error = EVAL_ERROR_VALUE_IS_NAN;
+ }
+ else if(unlikely(isinf(exp->result))) {
+ if(exp->error == EVAL_ERROR_OK)
+ exp->error = EVAL_ERROR_VALUE_IS_INFINITE;
+ }
+ else if(unlikely(exp->error == EVAL_ERROR_UNKNOWN_VARIABLE)) {
+ // although there is an unknown variable
+ // the expression was evaluated successfully
+ exp->error = EVAL_ERROR_OK;
+ }
if(exp->error != EVAL_ERROR_OK) {
exp->result = NAN;