From d16b005b490eabeda823c3fb00fef9329a4cf649 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Thu, 31 May 2012 23:31:48 +0200 Subject: Handle mpq_class(0,1) --- gmpxx.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'gmpxx.h') 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"); -- cgit v1.2.1