2 rational.hh -- declare rational helpers
4 source file of the Flower Library
6 (c) 1997--1998 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 truncated () const;
50 operator bool () const;
51 operator int () const;
52 operator double () const;
53 Rational operator - () const;
58 Rational (int, int =1);
60 Rational (Rational const&);
62 Rational &operator = (Rational const &);
63 Rational &operator *= (Rational);
64 Rational &operator /= (Rational);
65 Rational &operator += (Rational);
66 Rational &operator -= (Rational);
67 static int compare (Rational const&, Rational const&);
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);