Skip to content

Commit d2ea3d9

Browse files
author
Marco Bodrato
committed
gmpxx.h: Special handling for mpq==0
1 parent b170a46 commit d2ea3d9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

gmpxx.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* gmpxx.h -- C++ class wrapper for GMP types. -*- C++ -*-
22
3-
Copyright 2001-2003, 2006, 2008, 2011-2015 Free Software Foundation, Inc.
3+
Copyright 2001-2003, 2006, 2008, 2011-2015, 2018 Free Software
4+
Foundation, Inc.
45
56
This file is part of the GNU MP Library.
67
@@ -981,11 +982,15 @@ struct __gmp_binary_equal
981982
{ return mpq_equal(q, r) != 0; }
982983

983984
static bool eval(mpq_srcptr q, unsigned long int l)
984-
{ return mpz_cmp_ui(mpq_denref(q), 1) == 0 && mpz_cmp_ui(mpq_numref(q), l) == 0; }
985+
{ return ((__GMPXX_CONSTANT(l) && l == 0) ||
986+
mpz_cmp_ui(mpq_denref(q), 1) == 0) &&
987+
mpz_cmp_ui(mpq_numref(q), l) == 0; }
985988
static bool eval(unsigned long int l, mpq_srcptr q)
986989
{ return eval(q, l); }
987990
static bool eval(mpq_srcptr q, signed long int l)
988-
{ return mpz_cmp_ui(mpq_denref(q), 1) == 0 && mpz_cmp_si(mpq_numref(q), l) == 0; }
991+
{ return ((__GMPXX_CONSTANT(l) && l == 0) ||
992+
mpz_cmp_ui(mpq_denref(q), 1) == 0) &&
993+
mpz_cmp_si(mpq_numref(q), l) == 0; }
989994
static bool eval(signed long int l, mpq_srcptr q)
990995
{ return eval(q, l); }
991996
static bool eval(mpq_srcptr q, double d)

tests/cxx/t-ops2qf.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* Test mp*_class operators and functions.
22
3-
Copyright 2011, 2012 Free Software Foundation, Inc.
3+
Copyright 2011, 2012, 2018 Free Software Foundation, Inc.
44
55
This file is part of the GNU MP Library test suite.
66

0 commit comments

Comments
 (0)