X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Frational.cc;h=c5019afbd5a5d1fa6563a461e024ced7df70d21c;hb=bf8dede0799f6f73fc75eed7a2ce6fa4b774d9ce;hp=11aaf1e23b6ce457df53985ca52e62e7143d7708;hpb=f374663d1f993ba98c784afc6df1c9b50ba8fcc7;p=lilypond.git diff --git a/flower/rational.cc b/flower/rational.cc index 11aaf1e23b..c5019afbd5 100644 --- a/flower/rational.cc +++ b/flower/rational.cc @@ -3,7 +3,7 @@ source file of the Flower Library - (c) 1997--2000 Han-Wen Nienhuys + (c) 1997--2003 Han-Wen Nienhuys */ #include #include @@ -17,12 +17,15 @@ Rational::operator double () const return (double)sign_ * num_ / den_; } +#ifdef STREAM_SUPPORT ostream & operator << (ostream &o, Rational r) { - o << r.str (); + o << r.string (); return o; } +#endif + Rational Rational::trunc_rat () const @@ -63,11 +66,13 @@ int gcd (int a, int b) return b; } +#if 0 static int lcm (int a, int b) { return abs (a*b / gcd (a,b)); } +#endif void Rational::set_infinite (int s) @@ -144,12 +149,7 @@ Rational::compare (Rational const &r, Rational const &s) return 0; else { - /* - TODO: fix this code; (r-s).sign() is too expensive. - - return r.sign_ * ::sign (r.num_ * s.den_ - s.num_ * r.den_); - */ - return (r - s).sign (); + return r.sign_ * ::sign (int (r.num_ * s.den_) - int (s.num_ * r.den_)); } } @@ -276,27 +276,18 @@ Rational::operator -= (Rational r) return (*this += r); } -/* - be paranoid about overiding libg++ stuff - */ -Rational & -Rational::operator = (Rational const &r) -{ - copy (r); - return *this; -} - String -Rational::str () const +Rational::to_string () const { if (infty_b ()) { String s (sign_ > 0 ? "" : "-" ); return String (s + "infinity"); } - String s = to_str (num ()); + + String s = ::to_string (num ()); if (den () != 1 && num ()) - s += "/" + to_str (den ()); + s += "/" + ::to_string (den ()); return s; }