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 #define Rational MyRational
20 #include "arithmetic-operator.hh"
24 Rational numbers. Included is support for + and - infinity.
31 -2,2 is - and + infinity.
32 -1,1 is negative and positive.
36 unsigned int num_, den_;
38 void copy (Rational const &);
41 void set_infinite (int sign);
42 bool infty_b () const;
44 int num () const { return sign_ * num_; }
45 int den () const { return den_; }
46 int num_i () const { return sign_ * num_; }
47 int den_i () const { return den_; }
48 Rational trunc_rat () const;
49 Rational div_rat (Rational) const;
50 Rational mod_rat (Rational) const;
52 operator bool () const;
53 operator int () const;
54 operator double () const;
55 Rational operator - () const;
60 Rational (int, int =1);
62 Rational (Rational const&r) { copy (r);}
64 Rational &operator = (Rational const &);
65 Rational &operator *= (Rational);
66 Rational &operator /= (Rational);
67 Rational &operator += (Rational);
68 Rational &operator -= (Rational);
69 Rational &operator %= (Rational);
70 static int compare (Rational const&, Rational const&);
75 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, / );
76 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, + );
77 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, * );
78 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, - );
79 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, % );
81 INSTANTIATE_COMPARE (Rational const&, Rational::compare);
83 int compare (Rational const&,Rational const&);
84 int sign (Rational r);
87 Rational::copy (Rational const&r)
96 operator << (ostream &, Rational);