END_TEST START_TEST (test_util_NegZero) { double d = util_NegZero(); fail_unless(d == 0, "util_NegZero() did not even return a zero!"); fail_unless( util_isNegZero(d) ); }
END_TEST START_TEST (test_SBML_parseFormula_negZero) { ASTNode_t *r = SBML_parseFormula("-0.0"); fail_unless( ASTNode_getType(r) == AST_REAL, NULL ); fail_unless( util_isNegZero(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); } } }
/** * 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); } } }