2 rational.hh -- declare rational helpers
4 source file of the Flower Library
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
15 #include "arithmetic-operator.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_; }
42 int num_i () const { return sign_ * num_; }
43 int den_i () const { return den_; }
44 Rational trunc_rat () const;
45 Rational div_rat (Rational) const;
46 Rational mod_rat (Rational) const;
48 operator bool () const;
49 operator int () const;
50 operator double () const;
51 Rational operator - () const;
56 Rational (int, int =1);
58 Rational (Rational const&r) { copy (r);}
60 Rational &operator = (Rational const &);
61 Rational &operator *= (Rational);
62 Rational &operator /= (Rational);
63 Rational &operator += (Rational);
64 Rational &operator -= (Rational);
65 Rational &operator %= (Rational);
66 static int compare (Rational const&, Rational const&);
71 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, / );
72 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, + );
73 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, * );
74 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, - );
75 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, % );
77 INSTANTIATE_COMPARE (Rational const&, Rational::compare);
79 int compare (Rational const&,Rational const&);
80 int sign (Rational r);
83 Rational::copy (Rational const&r)
92 operator << (ostream &, Rational);