2 rational.hh -- declare rational helpers
4 source file of the Flower Library
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 #include "arithmetic-operator.hh"
15 #include "flower-proto.hh"
20 Rational numbers. Included is support for + and - infinity.
27 -2,2 is - and + infinity.
28 -1,1 is negative and positive.
32 unsigned int num_, den_;
34 void copy (Rational const &);
37 void set_infinite (int sign);
38 bool infty_b () const;
40 int num () const { return sign_ * num_; }
41 int den () const { return den_; }
43 Rational trunc_rat () const;
44 Rational div_rat (Rational) const;
45 Rational mod_rat (Rational) const;
47 operator bool () const;
48 operator int () const;
49 operator double () const;
50 Rational operator - () const;
55 Rational (int, int =1);
57 Rational (Rational const&r) { copy (r);}
59 Rational &operator = (Rational const &);
60 Rational &operator *= (Rational);
61 Rational &operator /= (Rational);
62 Rational &operator += (Rational);
63 Rational &operator -= (Rational);
64 Rational &operator %= (Rational);
65 static int compare (Rational const&, Rational const&);
70 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, / );
71 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, + );
72 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, * );
73 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, - );
74 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, % );
76 INSTANTIATE_COMPARE (Rational const&, Rational::compare);
78 int compare (Rational const&,Rational const&);
79 int sign (Rational r);
82 Rational::copy (Rational const&r)
90 operator << (ostream &, Rational);
92 const Rational infinity_rat = INT_MAX;