2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 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/>.
24 #include "flower-proto.hh"
25 #include "std-string.hh"
29 Rational numbers. Included is support for + and - infinity.
37 -2,2 is - and + infinity.
38 -1,1 is negative and positive.
44 void copy (Rational const &);
47 void set_infinite (int sign);
48 bool is_infinity () const;
50 I64 numerator () const { return sign_ * num_; }
51 I64 denominator () const { return den_; }
52 I64 num () const { return numerator (); }
53 I64 den () const { return denominator (); }
55 Rational trunc_rat () const;
56 Rational div_rat (Rational) const;
57 Rational mod_rat (Rational) const;
58 Rational abs () const;
62 operator double () const { return to_double (); }
63 double to_double () const;
65 Rational operator - () const;
73 explicit Rational (I64, I64);
74 explicit Rational (double);
75 Rational (Rational const &r) { copy (r);}
76 Rational &operator = (Rational const &r)
82 Rational &operator *= (Rational);
83 Rational &operator /= (Rational);
84 Rational &operator += (Rational);
85 Rational &operator -= (Rational);
86 Rational &operator %= (Rational);
87 static int compare (Rational const &, Rational const &);
89 string to_string () const;
92 #include "arithmetic-operator.hh"
94 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, / );
95 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, +);
96 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, *);
97 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, -);
98 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, % );
100 INSTANTIATE_COMPARE (Rational const &, Rational::compare);
102 int compare (Rational const &, Rational const &);
103 int sign (Rational r);
106 Rational::copy (Rational const &r)
115 operator << (ostream &, Rational);
118 const Rational infinity_rat (U64_MAX);
120 #endif // RATIONAL_HH