END_TEST START_TEST (test_FormulaTokenizer_numbers_nan_inf) { FormulaTokenizer_t *ft = FormulaTokenizer_createFromFormula("NaN Inf"); Token_t *t; t = FormulaTokenizer_nextToken(ft); fail_unless( t->type == TT_REAL ); fail_unless( t->value.real != t->value.real ); Token_free(t); t = FormulaTokenizer_nextToken(ft); fail_unless( t->type == TT_REAL ); fail_unless( util_isInf(t->value.real) == 1 ); Token_free(t); t = FormulaTokenizer_nextToken(ft); fail_unless( t->type == TT_END ); Token_free(t); FormulaTokenizer_free(ft); }
std::string CODEExporterC::exportNumber(double number) { if (util_isNaN(number)) return "NaN"; if (util_isInf(number)) return "INFINITY"; std::stringstream str; str << number; return str.str(); }
END_TEST START_TEST (test_SBML_parseFormula_negInf) { ASTNode_t *r = SBML_parseFormula("-inf"); fail_unless( ASTNode_getType(r) == AST_REAL, NULL ); fail_unless( util_isInf(ASTNode_getReal(r)) == -1, NULL ); fail_unless( ASTNode_getNumChildren(r) == 0, NULL ); ASTNode_free(r); }
/** * Formats the given ASTNode as a real number and appends the result to * the given StringBuffer. */ void L3FormulaFormatter_formatReal (StringBuffer_t *sb, const ASTNode_t *node, const L3ParserSettings_t *settings) { double value = ASTNode_getReal(node); int sign; char * units; if (ASTNode_isInteger(node)) { value = ASTNode_getInteger(node); } if (util_isNaN(value)) { StringBuffer_append(sb, "NaN"); } else if ((sign = util_isInf(value)) != 0) { if (sign == -1) { StringBuffer_appendChar(sb, '-'); } StringBuffer_append(sb, "INF"); } else if (util_isNegZero(value)) { StringBuffer_append(sb, "-0"); } else { if (ASTNode_getType(node) == AST_REAL_E) { StringBuffer_appendExp(sb, value); } else { StringBuffer_appendReal(sb, value); } } if (L3ParserSettings_getParseUnits(settings)) { if (ASTNode_hasUnits(node)) { StringBuffer_appendChar( sb, ' '); units = ASTNode_getUnits(node); StringBuffer_append( sb, units); safe_free(units); } } }
END_TEST START_TEST (test_util_isInf) { fail_unless( util_isInf( util_PosInf() ) == 1 ); fail_unless( util_isInf( util_NegInf() ) == -1 ); fail_unless( util_isInf( util_NaN() ) == 0 ); fail_unless( util_isInf( util_NegZero() ) == 0 ); fail_unless( util_isInf(0.0) == 0 ); fail_unless( util_isInf(1.2) == 0 ); }
/** * Formats the given ASTNode as a real number and returns the result as * a string. */ char * FormulaGraphvizFormatter_formatReal (const ASTNode_t *node) { StringBuffer_t *p = StringBuffer_create(128); double value = ASTNode_getReal(node); int sign; char *s; if (util_isNaN(value)) { s = "NaN"; } else if ((sign = util_isInf(value)) != 0) { if (sign == -1) { s = "-INF"; } else { s = "INF"; } } else if (util_isNegZero(value)) { s = "-0"; } else { StringBuffer_appendReal(p, value); s = StringBuffer_toString(p); } free(p); return s; }
/** * Formats the given ASTNode as a real number and appends the result to * the given StringBuffer. */ void FormulaFormatter_formatReal (StringBuffer_t *sb, const ASTNode_t *node) { double value = ASTNode_getReal(node); int sign; if (util_isNaN(value)) { StringBuffer_append(sb, "NaN"); } else if ((sign = util_isInf(value)) != 0) { if (sign == -1) { StringBuffer_appendChar(sb, '-'); } StringBuffer_append(sb, "INF"); } else if (util_isNegZero(value)) { StringBuffer_append(sb, "-0"); } else { if (ASTNode_getType(node) == AST_REAL_E) { StringBuffer_appendExp(sb, value); } else { StringBuffer_appendReal(sb, value); } } }