summaryrefslogtreecommitdiff
path: root/gmpxx.h
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2012-05-31 23:31:48 +0200
committerMarc Glisse <marc.glisse@inria.fr>2012-05-31 23:31:48 +0200
commitd16b005b490eabeda823c3fb00fef9329a4cf649 (patch)
tree16a94165cc18e9e147686b0232a9c056eca7bf08 /gmpxx.h
parent024f07177c7e393e9ea0ab804998ec12408bd74d (diff)
downloadgmp-d16b005b490eabeda823c3fb00fef9329a4cf649.tar.gz
Handle mpq_class(0,1)
Diffstat (limited to 'gmpxx.h')
-rw-r--r--gmpxx.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/gmpxx.h b/gmpxx.h
index d47757864..450f37568 100644
--- a/gmpxx.h
+++ b/gmpxx.h
@@ -1641,7 +1641,14 @@ public:
explicit __gmp_expr(const char *s, int base = 0)
{
mpq_init (mp);
- if (mpq_set_str(mp, s, base) != 0)
+ // If s is the literal 0, we meant to call another constructor.
+ // If s just happens to evaluate to 0, we would crash, so whatever.
+ if (s == 0)
+ {
+ // Don't turn mpq_class(0,0) into 0
+ mpz_set_si(mpq_denref(mp), base);
+ }
+ else if (mpq_set_str(mp, s, base) != 0)
{
mpq_clear (mp);
throw std::invalid_argument ("mpq_set_str");