]> git.donarmstrong.com Git - lilypond.git/commitdiff
Bugfix: Rational.cc: Modulo and trunc did not work with negative numbers.
authorRune Zedeler <rune@lilypond.org>
Tue, 23 Oct 2007 04:26:35 +0000 (06:26 +0200)
committerRune Zedeler <rune@lilypond.org>
Tue, 23 Oct 2007 04:26:35 +0000 (06:26 +0200)
This is a library fix that did not show any bugs in lilypond - because
lilypond does not use modulus of negative rationals.

flower/rational.cc

index 724f0d99ca5b526dfc5f067decfbaf2066f7796c..4205b1d683042153a4fe41dfa6651bb343c75d70 100644 (file)
@@ -50,7 +50,9 @@ Rational::abs () const
 Rational
 Rational::trunc_rat () const
 {
-  return Rational (num_ - (num_ % den_), den_);
+  if (is_infinity())
+    return *this;
+  return Rational ((num_ - (num_ % den_)) * sign_, den_);
 }
 
 Rational::Rational ()
@@ -79,6 +81,7 @@ void
 Rational::set_infinite (int s)
 {
   sign_ = ::sign (s) * 2;
+  num_ = 1;
 }
 
 Rational