From: Han-Wen Nienhuys Date: Sun, 24 Dec 2006 15:08:49 +0000 (+0100) Subject: explicit ctors for rational. X-Git-Tag: release/2.10.5-1~13 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=b38c8e67d0a93e8b9f893309669de1db606bf0a2;p=lilypond.git explicit ctors for rational. --- diff --git a/flower/include/rational.hh b/flower/include/rational.hh index bc64465cfe..ac1a6d12fc 100644 --- a/flower/include/rational.hh +++ b/flower/include/rational.hh @@ -54,8 +54,9 @@ public: Initialize to 0. */ Rational (); - Rational (int, int); - Rational (double); + Rational (int); + explicit Rational (int, int); + explicit Rational (double); Rational (Rational const &r) { copy (r);} Rational &operator = (Rational const &r) { @@ -98,6 +99,6 @@ ostream & operator << (ostream &, Rational); #endif -const Rational infinity_rat = INT_MAX; +const Rational infinity_rat (INT_MAX); #endif // RATIONAL_HH diff --git a/flower/rational.cc b/flower/rational.cc index 1014607f80..0d9515c367 100644 --- a/flower/rational.cc +++ b/flower/rational.cc @@ -56,6 +56,17 @@ Rational::Rational (int n, int d) normalize (); } +Rational::Rational (int n) +{ + sign_ = ::sign (n); + num_ = ::abs (n); + den_ = 1; +} + + +/* + We can actually do a little better. See Knuth 4.5.2 + */ static inline int gcd (int a, int b) {