]> git.donarmstrong.com Git - lilypond.git/commitdiff
explicit ctors for rational.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 24 Dec 2006 15:08:49 +0000 (16:08 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 24 Dec 2006 15:36:19 +0000 (16:36 +0100)
flower/include/rational.hh
flower/rational.cc

index bc64465cfe5db4c5758a4aa6c4bcc3de6609b449..ac1a6d12fc1e0ae01eccc2bb3d9d6ed65cfd83b1 100644 (file)
@@ -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
index 1014607f808b4e73616ff484f34b68044dbce036..0d9515c367a59e8878b5228475c3dd2b9f5d18d0 100644 (file)
@@ -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)
 {