END_TEST START_TEST (test_util_PosInf) { double d = util_PosInf(); if ( util_isFinite(d) || util_isNaN(d) || d <= 0) { fail("util_PosInf() did not return +Inf."); } }
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 ); }
/** * Converts the given Token (which must be of type TT_NAME) to a TT_REAL * NaN or Inf as appropriate. */ void Token_convertNaNInf (Token_t *t) { if ( !strcmp_insensitive(t->value.name, "NaN") ) { safe_free(t->value.name); t->type = TT_REAL; t->value.real = util_NaN(); } else if ( !strcmp_insensitive(t->value.name, "Inf") ) { safe_free(t->value.name); t->type = TT_REAL; t->value.real = util_PosInf(); } }
END_TEST START_TEST (test_FormulaFormatter_formatReal) { StringBuffer_t *sb = StringBuffer_create(42); char *s = StringBuffer_getBuffer(sb); ASTNode_t *n = ASTNode_create(); /** 1.2 **/ ASTNode_setReal(n, 1.2); FormulaFormatter_formatReal(sb, n); fail_unless( !strcmp(s, "1.2"), NULL ); StringBuffer_reset(sb); /** 1e-100 **/ ASTNode_setRealWithExponent(n, 1, -100); FormulaFormatter_formatReal(sb, n); fail_unless( !strcmp(s, "1.000000e-100"), NULL ); StringBuffer_reset(sb); /** NaN **/ ASTNode_setReal(n, util_NaN()); FormulaFormatter_formatReal(sb, n); fail_unless( !strcmp(s, "NaN"), NULL ); StringBuffer_reset(sb); /** Inf **/ ASTNode_setReal(n, util_PosInf()); FormulaFormatter_formatReal(sb, n); fail_unless( !strcmp(s, "INF"), NULL ); StringBuffer_reset(sb); /** -Inf **/ ASTNode_setReal(n, util_NegInf()); FormulaFormatter_formatReal(sb, n); fail_unless( !strcmp(s, "-INF"), NULL ); StringBuffer_reset(sb); /** -0 **/ ASTNode_setReal(n, util_NegZero()); FormulaFormatter_formatReal(sb, n); fail_unless( !strcmp(s, "-0"), NULL ); StringBuffer_reset(sb); StringBuffer_free(sb); ASTNode_free(n); }
LIBSBML_EXTERN double util_NegZero (void) { return -1.0 / util_PosInf(); }