]> git.donarmstrong.com Git - lilypond.git/commitdiff
compare LilyPond Rationals without unnecessary overflow; issue 4180
authorKeith OHara <k-ohara5a5a@oco.net>
Sun, 28 Dec 2014 05:39:55 +0000 (21:39 -0800)
committerKeith OHara <k-ohara5a5a@oco.net>
Sun, 11 Jan 2015 03:44:55 +0000 (19:44 -0800)
This reverses part of commit 19125bf1, which said that (r-s).sign() was
too expensive, but I saw no change (within 0.1%) in compilation times.

flower/rational.cc

index a6f82d826e9185fdbab3250388d667d1cce46167..559e1646a0cade47b932d7cfab048f0feb641da8 100644 (file)
@@ -216,11 +216,11 @@ Rational::compare (Rational const &r, Rational const &s)
     return -1;
   else if (r.sign_ > s.sign_)
     return 1;
-  else if (r.is_infinity ())
+  else if (r.is_infinity ()) // here s is also infinite with the same sign
     return 0;
-  else if (r.sign_ == 0)
+  else if (r.sign_ == 0) // here s.sign_ is also zero
     return 0;
-  return r.sign_ * ::sign ((I64) (r.num_ * s.den_) - (I64) (s.num_ * r.den_));
+  return ::sign (r - s);
 }
 
 int