summaryrefslogtreecommitdiff
path: root/src/util/rational.h
diff options
context:
space:
mode:
authorTim King <taking@cs.nyu.edu>2010-05-25 21:45:18 +0000
committerTim King <taking@cs.nyu.edu>2010-05-25 21:45:18 +0000
commit2635899db4a7622a206e2ec562d01e3337a92199 (patch)
tree43222be9c81680f93120e8e82100b8d46b821f2a /src/util/rational.h
parente87c14798b99ccb586751d291b0eeb3208265bd8 (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/rational.h')
-rw-r--r--src/util/rational.h18
1 files changed, 17 insertions, 1 deletions
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) {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback