[Gmp-commit] /var/hg/gmp: Handle mpq_class(0,1)
mercurial at gmplib.org
mercurial at gmplib.org
Thu May 31 23:31:51 CEST 2012
details: /var/hg/gmp/rev/f773c0597bae
changeset: 15030:f773c0597bae
user: Marc Glisse <marc.glisse at inria.fr>
date: Thu May 31 23:31:48 2012 +0200
description:
Handle mpq_class(0,1)
diffstat:
ChangeLog | 5 +++++
gmpxx.h | 9 ++++++++-
tests/cxx/t-constr.cc | 1 +
3 files changed, 14 insertions(+), 1 deletions(-)
diffs (42 lines):
diff -r 22a220f9ca2e -r f773c0597bae ChangeLog
--- a/ChangeLog Wed May 30 19:53:11 2012 +0200
+++ b/ChangeLog Thu May 31 23:31:48 2012 +0200
@@ -1,3 +1,8 @@
+2012-05-31 Marc Glisse <marc.glisse at inria.fr>
+
+ * gmpxx.h (mpq_class::mpq_class): Handle mpq_class(0,1).
+ * tests/cxx/t-constr.cc: Test it.
+
2012-05-30 Torbjorn Granlund <tege at gmplib.org>
* mpn/x86_64 (FUNC_ENTRY): New name for DOS64_ENTRY.
diff -r 22a220f9ca2e -r f773c0597bae gmpxx.h
--- a/gmpxx.h Wed May 30 19:53:11 2012 +0200
+++ b/gmpxx.h Thu May 31 23:31:48 2012 +0200
@@ -1641,7 +1641,14 @@
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");
diff -r 22a220f9ca2e -r f773c0597bae tests/cxx/t-constr.cc
--- a/tests/cxx/t-constr.cc Wed May 30 19:53:11 2012 +0200
+++ b/tests/cxx/t-constr.cc Thu May 31 23:31:48 2012 +0200
@@ -320,6 +320,7 @@
const char *a = "FFFF";
int base = 16;
mpq_class b(a, base); ASSERT_ALWAYS(b == 65535u);
+ mpq_class c(0, 1); ASSERT_ALWAYS(c == 0);
}
// mpq_class(const std::string &)
More information about the gmp-commit
mailing list