2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 #include "flower-proto.hh"
24 #include "std-string.hh"
28 Rational numbers. Included is support for + and - infinity.
36 -2,2 is - and + infinity.
37 -1,1 is negative and positive.
43 void copy (Rational const &);
46 void set_infinite (int sign);
47 bool is_infinity () const;
49 I64 numerator () const { return sign_ * num_; }
50 I64 denominator () const { return den_; }
51 I64 num () const { return numerator (); }
52 I64 den () const { return denominator (); }
54 Rational trunc_rat () const;
55 Rational div_rat (Rational) const;
56 Rational mod_rat (Rational) const;
57 Rational abs () const;
61 operator double () const { return to_double (); }
62 double to_double () const;
64 Rational operator - () const;
72 explicit Rational (I64, I64);
73 explicit Rational (double);
74 Rational (Rational const &r) { copy (r);}
75 Rational &operator = (Rational const &r)
77 copy (r); return *this;
80 Rational &operator *= (Rational);
81 Rational &operator /= (Rational);
82 Rational &operator += (Rational);
83 Rational &operator -= (Rational);
84 Rational &operator %= (Rational);
85 static int compare (Rational const &, Rational const &);
87 string to_string () const;
90 #include "arithmetic-operator.hh"
92 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, /);
93 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, +);
94 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, *);
95 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, -);
96 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, %);
98 INSTANTIATE_COMPARE (Rational const &, Rational::compare);
100 int compare (Rational const &, Rational const &);
101 int sign (Rational r);
104 Rational::copy (Rational const &r)
113 operator << (ostream &, Rational);
116 const Rational infinity_rat (U64_MAX);
118 #endif // RATIONAL_HH