2 rational.hh -- declare rational helpers
4 source file of the Flower Library
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
15 #define Rational MyRational
20 #include "arithmetic-operator.hh"
25 unsigned int num_, den_;
27 void copy (Rational const &);
29 void set_infinite (int sign);
30 bool infty_b () const;
32 int num () const { return sign_ * num_; }
33 int den () const { return den_; }
34 Rational truncated () const;
36 operator bool () const;
37 operator int () const;
38 operator double () const;
39 operator String () const;
40 Rational operator - () const;
42 Rational (int, int =1);
44 Rational (Rational const&);
46 Rational &operator = (Rational const &);
47 Rational &operator *= (Rational);
48 Rational &operator /= (Rational);
49 Rational &operator += (Rational);
50 Rational &operator -= (Rational);
51 static int compare (Rational const&, Rational const&);
56 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, / );
57 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, + );
58 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, * );
59 IMPLEMENT_ARITHMETIC_OPERATOR (Rational, - );
61 INSTANTIATE_COMPARE (Rational const&, Rational::compare);
63 int compare (Rational const&,Rational const&);
64 int sign (Rational r);
67 Rational::copy (Rational const&r)
76 operator << (ostream &, Rational);