source file of the Flower Library
- (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
*/
#ifndef RATIONAL_HH
#define RATIONAL_HH
#include "std-string.hh"
-
-#include "std-string.hh"
+#include <limits.h>
/**
Rational numbers. Included is support for + and - infinity.
*/
int sign_;
unsigned int num_, den_;
- void normalise ();
+ void normalize ();
void copy (Rational const &);
public:
Rational trunc_rat () const;
Rational div_rat (Rational) const;
Rational mod_rat (Rational) const;
+ Rational abs () const;
void negate ();
int to_int () const;
- operator bool () const;
- operator double () const;
+
+ operator double () const { return to_double (); }
+ double to_double () const;
Rational operator - () const;
/**
*/
Rational ();
Rational (int);
- Rational (int, int);
- Rational (double);
+ explicit Rational (int, int);
+ explicit Rational (double);
Rational (Rational const &r) { copy (r);}
Rational &operator = (Rational const &r)
{
};
#include "arithmetic-operator.hh"
+
IMPLEMENT_ARITHMETIC_OPERATOR (Rational, /);
IMPLEMENT_ARITHMETIC_OPERATOR (Rational, +);
IMPLEMENT_ARITHMETIC_OPERATOR (Rational, *);
operator << (ostream &, Rational);
#endif
-const Rational infinity_rat = INT_MAX;
+const Rational infinity_rat (INT_MAX);
#endif // RATIONAL_HH