]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/rational.cc
Merge branch 'master' of ssh://kainhofer@git.sv.gnu.org/srv/git/lilypond into kainhofer
[lilypond.git] / flower / rational.cc
index 6822703256a410433e3235c4fa263b389357a08a..4205b1d683042153a4fe41dfa6651bb343c75d70 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the Flower Library
 
-  (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include "rational.hh"
@@ -16,7 +16,8 @@ using namespace std;
 #include "string-convert.hh"
 #include "libc-extension.hh"
 
-Rational::operator double () const
+double
+Rational::to_double () const
 {
   if (sign_ == -1 || sign_ == 1 || sign_ == 0)
     return ((double)sign_) * num_ / den_;
@@ -49,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 ()
@@ -78,6 +81,7 @@ void
 Rational::set_infinite (int s)
 {
   sign_ = ::sign (s) * 2;
+  num_ = 1;
 }
 
 Rational