From a949a2cd08ca8e7539c0556eed67976881b8840f Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 9 Jan 2012 22:49:33 +0000 Subject: [PATCH] math: fix an infinite loop in the real number print function. --- src/real.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/real.cpp b/src/real.cpp index a01f233d..c2dfcaba 100644 --- a/src/real.cpp +++ b/src/real.cpp @@ -1274,6 +1274,12 @@ void real::print(int ndigits) const x = -x; } + if (!x) + { + printf("0.0\n"); + return; + } + /* Normalise x so that mantissa is in [1..9.999] */ /* FIXME: better use int64_t when the cast is implemented */ int exponent = ceil(log10(x));