diff options
author | Tim King <taking@cs.nyu.edu> | 2010-05-25 21:45:18 +0000 |
---|---|---|
committer | Tim King <taking@cs.nyu.edu> | 2010-05-25 21:45:18 +0000 |
commit | 2635899db4a7622a206e2ec562d01e3337a92199 (patch) | |
tree | 43222be9c81680f93120e8e82100b8d46b821f2a /src/util | |
parent | e87c14798b99ccb586751d291b0eeb3208265bd8 (diff) |
Added Rational constructors that only take a numerator. The const char* Rational and Integer constructors are now explicit. This means that 'Integer = 3;' and so on are no longer permitted. This closes bug 121.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/integer.h | 2 | ||||
-rw-r--r-- | src/util/rational.h | 18 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/util/integer.h b/src/util/integer.h index c019144a9..41582d8db 100644 --- a/src/util/integer.h +++ b/src/util/integer.h @@ -56,7 +56,7 @@ public: * For more information about what is a valid rational string, * see GMP's documentation for mpq_set_str(). */ - Integer(const char * s, int base = 10): d_value(s,base) {} + explicit Integer(const char * s, int base = 10): d_value(s,base) {} Integer(const std::string& s, unsigned base = 10) : d_value(s, base) {} Integer(const Integer& q) : d_value(q.d_value) {} diff --git a/src/util/rational.h b/src/util/rational.h index 53a7e9060..8218984a7 100644 --- a/src/util/rational.h +++ b/src/util/rational.h @@ -75,7 +75,7 @@ public: * For more information about what is a valid rational string, * see GMP's documentation for mpq_set_str(). */ - Rational(const char * s, int base = 10): d_value(s,base) { + explicit Rational(const char * s, int base = 10): d_value(s,base) { d_value.canonicalize(); } Rational(const std::string& s, unsigned base = 10) : d_value(s, base) { @@ -90,6 +90,22 @@ public: } /** + * Constructs a canonical Rational from a numerator. + */ + Rational(signed int n) : d_value(n,1) { + d_value.canonicalize(); + } + Rational(unsigned int n) : d_value(n,1) { + d_value.canonicalize(); + } + Rational(signed long int n) : d_value(n,1) { + d_value.canonicalize(); + } + Rational(unsigned long int n) : d_value(n,1) { + d_value.canonicalize(); + } + + /** * Constructs a canonical Rational from a numerator and denominator. */ Rational(signed int n, signed int d) : d_value(n,d) { |