2 rational.hh -- declare rational helpers
4 source file of the Flower Library
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
16 Rational numbers. Included is support for + and - infinity.
23 -2,2 is - and + infinity.
24 -1,1 is negative and positive.
28 unsigned int num_, den_;
30 void copy (Rational const &);
33 void set_infinite (int sign);
34 bool is_infinity () const;
36 int num () const { return sign_ * num_; }
37 int den () const { return den_; }
39 Rational trunc_rat () const;
40 Rational div_rat (Rational) const;
41 Rational mod_rat (Rational) const;
43 // operator bool () const;
45 operator double () const;
46 Rational operator - () const;
54 Rational (Rational const&r) { copy (r);}
55 Rational &operator = (Rational const &r) {
56 copy (r); return *this;
59 Rational &operator *= (Rational);
60 Rational &operator /= (Rational);
61 Rational &operator += (Rational);
62 Rational &operator -= (Rational);
63 Rational &operator %= (Rational);
64 static int compare (Rational const&, Rational const&);
66 String to_string () const;
69 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, / );
70 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, + );
71 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, * );
72 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, - );
73 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, % );
75 INSTANTIATE_COMPARE (Rational const&, Rational::compare);
77 int compare (Rational const&,Rational const&);
78 int sign (Rational r);
81 Rational::copy (Rational const&r)
90 operator << (ostream &, Rational);
93 const Rational infinity_rat = INT_MAX;