]> git.donarmstrong.com Git - lilypond.git/commitdiff
rational cleanups: suppress some automatic conversions.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 22 Dec 2006 15:28:49 +0000 (16:28 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 24 Dec 2006 15:35:06 +0000 (16:35 +0100)
flower/include/rational.hh
flower/rational.cc

index 290d02b9601b9918938b33ba47447527ab3a0094..bc64465cfe5db4c5758a4aa6c4bcc3de6609b449 100644 (file)
@@ -28,7 +28,7 @@ class Rational
   */
   int sign_;
   unsigned int num_, den_;
-  void normalise ();
+  void normalize ();
   void copy (Rational const &);
 
 public:
@@ -43,9 +43,10 @@ public:
   Rational trunc_rat () const;
   Rational div_rat (Rational) const;
   Rational mod_rat (Rational) const;
+  Rational abs () const;
   void negate ();
   int to_int () const;
-  operator bool () const;
+
   operator double () const;
 
   Rational operator - () const;
@@ -53,7 +54,6 @@ public:
      Initialize to 0.
   */
   Rational ();
-  Rational (int);
   Rational (int, int);
   Rational (double);
   Rational (Rational const &r) { copy (r);}
@@ -73,6 +73,7 @@ public:
 };
 
 #include "arithmetic-operator.hh"
+
 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, /);
 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, +);
 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, *);
index a0c0d22410e235726eeee037b760fee1f7dcaef9..1014607f808b4e73616ff484f34b68044dbce036 100644 (file)
@@ -20,10 +20,6 @@ Rational::operator double () const
   return ((double)sign_) * num_ / den_;
 }
 
-Rational::operator bool () const
-{
-  return sign_ && num_;
-}
 
 #ifdef STREAM_SUPPORT
 ostream &
@@ -34,6 +30,12 @@ operator << (ostream &o, Rational r)
 }
 #endif
 
+Rational
+Rational::abs () const
+{
+  return Rational (num_, den_);
+}
+
 Rational
 Rational::trunc_rat () const
 {
@@ -49,16 +51,9 @@ Rational::Rational ()
 Rational::Rational (int n, int d)
 {
   sign_ = ::sign (n) * ::sign (d);
-  num_ = abs (n);
-  den_ = abs (d);
-  normalise ();
-}
-
-Rational::Rational (int n)
-{
-  sign_ = ::sign (n);
-  num_ = abs (n);
-  den_ = 1;
+  num_ = ::abs (n);
+  den_ = ::abs (d);
+  normalize ();
 }
 
 static inline
@@ -104,7 +99,7 @@ Rational::mod_rat (Rational div) const
 }
 
 void
-Rational::normalise ()
+Rational::normalize ()
 {
   if (!sign_)
     {
@@ -175,9 +170,9 @@ Rational::operator += (Rational r)
       int n = sign_ * num_ * (lcm / den_) + r.sign_ * r.num_ * (lcm / r.den_);
       int d = lcm;
       sign_ = ::sign (n) * ::sign (d);
-      num_ = abs (n);
-      den_ = abs (d);
-      normalise ();
+      num_ = ::abs (n);
+      den_ = ::abs (d);
+      normalize ();
     }
   return *this;
 }
@@ -207,19 +202,19 @@ Rational::Rational (double x)
 
       num_ = (unsigned int) (mantissa * FACT);
       den_ = (unsigned int) FACT;
-      normalise ();
+      normalize ();
       if (expt < 0)
        den_ <<= -expt;
       else
        num_ <<= expt;
-      normalise ();
+      normalize ();
     }
   else
     {
       num_ = 0;
       den_ = 1;
       sign_ = 0;
-      normalise ();
+      normalize ();
     }
 }
 
@@ -244,7 +239,7 @@ Rational::operator *= (Rational r)
   num_ *= r.num_;
   den_ *= r.den_;
 
-  normalise ();
+  normalize ();
  exit_func:
   return *this;
 }