diff options
Diffstat (limited to 'src/util/rational_cln_imp.h')
-rw-r--r-- | src/util/rational_cln_imp.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/util/rational_cln_imp.h b/src/util/rational_cln_imp.h index 583983829..ea9f7d055 100644 --- a/src/util/rational_cln_imp.h +++ b/src/util/rational_cln_imp.h @@ -69,7 +69,8 @@ private: public: - /** Creates a rational from a decimal string (e.g., <code>"1.5"</code>). + /** + * Creates a rational from a decimal string (e.g., <code>"1.5"</code>). * * @param dec a string encoding a decimal number in the format * <code>[0-9]*\.[0-9]*</code> @@ -166,10 +167,19 @@ public: * Returns the value of denominator of the Rational. * Note that this makes a deep copy of the denominator. */ - Integer getDenominator() const{ + Integer getDenominator() const { return Integer(cln::denominator(d_value)); } + /** + * Get a double representation of this Rational, which is + * approximate: truncation may occur, overflow may result in + * infinity, and underflow may result in zero. + */ + double getDouble() const { + return cln::double_approx(d_value); + } + Rational inverse() const { return Rational(cln::recip(d_value)); } |