From: David Gow Date: Thu, 7 Aug 2014 14:30:37 +0000 (+0800) Subject: "fixed" Rational::ToDouble(). X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=63554274d8ca1b51b47da55c978c3354a91567bc;p=ipdf%2Fcode.git "fixed" Rational::ToDouble(). Previously if the numerator or denominator was > the range of a double, Rational.ToDouble() would return NaN. We now check for this case, and discard precision accordingly. --- diff --git a/src/rational.h b/src/rational.h index bbd4c30..b019505 100644 --- a/src/rational.h +++ b/src/rational.h @@ -10,6 +10,8 @@ #include #include "arbint.h" #include "gmpint.h" +#include +#include namespace IPDF { @@ -171,7 +173,13 @@ struct Rational double ToDouble() const { - return (double)P/(double)Q; + T num = P, denom = Q; + while (Tabs(num) > T(DBL_MAX)) + { + num /= T(16); + denom /= T(16); + } + return ((double)(num))/((double)(denom)); } bool CheckAccuracy(double d, const char * msg, double threshold = 1e-3) const {