[Gmp-commit] /var/hg/gmp: Remove code duplication between __gmp_binary_greate...

mercurial at gmplib.org mercurial at gmplib.org
Thu Feb 14 18:55:01 CET 2013


details:   /var/hg/gmp/rev/69f663664fcb
changeset: 15433:69f663664fcb
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Thu Feb 14 18:54:58 2013 +0100
description:
Remove code duplication between __gmp_binary_greater and __gmp_binary_less.

diffstat:

 ChangeLog |   4 ++++
 gmpxx.h   |  62 ++------------------------------------------------------------
 2 files changed, 6 insertions(+), 60 deletions(-)

diffs (83 lines):

diff -r 5ee0a73b049c -r 69f663664fcb ChangeLog
--- a/ChangeLog	Thu Feb 14 13:04:36 2013 +0100
+++ b/ChangeLog	Thu Feb 14 18:54:58 2013 +0100
@@ -1,3 +1,7 @@
+2013-02-14  Marc Glisse  <marc.glisse at inria.fr>
+
+	* gmpxx.h (__gmp_binary_greater): Forward to __gmp_binary_less.
+
 2013-02-14 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mp_dv_tab.c (__gmp_digit_value_tab): Remove a line of unused values.
diff -r 5ee0a73b049c -r 69f663664fcb gmpxx.h
--- a/gmpxx.h	Thu Feb 14 13:04:36 2013 +0100
+++ b/gmpxx.h	Thu Feb 14 18:54:58 2013 +0100
@@ -1003,66 +1003,8 @@
 
 struct __gmp_binary_greater
 {
-  static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) > 0; }
-
-  static bool eval(mpz_srcptr z, unsigned long int l)
-  { return mpz_cmp_ui(z, l) > 0; }
-  static bool eval(unsigned long int l, mpz_srcptr z)
-  { return mpz_cmp_ui(z, l) < 0; }
-  static bool eval(mpz_srcptr z, signed long int l)
-  { return mpz_cmp_si(z, l) > 0; }
-  static bool eval(signed long int l, mpz_srcptr z)
-  { return mpz_cmp_si(z, l) < 0; }
-  static bool eval(mpz_srcptr z, double d)
-  { return mpz_cmp_d(z, d) > 0; }
-  static bool eval(double d, mpz_srcptr z)
-  { return mpz_cmp_d(z, d) < 0; }
-
-  static bool eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r) > 0; }
-
-  static bool eval(mpq_srcptr q, unsigned long int l)
-  { return mpq_cmp_ui(q, l, 1) > 0; }
-  static bool eval(unsigned long int l, mpq_srcptr q)
-  { return mpq_cmp_ui(q, l, 1) < 0; }
-  static bool eval(mpq_srcptr q, signed long int l)
-  { return mpq_cmp_si(q, l, 1) > 0; }
-  static bool eval(signed long int l, mpq_srcptr q)
-  { return mpq_cmp_si(q, l, 1) < 0; }
-  static bool eval(mpq_srcptr q, double d)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_cmp(q, temp) > 0);
-    mpq_clear(temp);
-    return b;
-  }
-  static bool eval(double d, mpq_srcptr q)
-  {
-    bool b;
-    mpq_t temp;
-    mpq_init(temp);
-    mpq_set_d(temp, d);
-    b = (mpq_cmp(temp, q) > 0);
-    mpq_clear(temp);
-    return b;
-  }
-
-  static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) > 0; }
-
-  static bool eval(mpf_srcptr f, unsigned long int l)
-  { return mpf_cmp_ui(f, l) > 0; }
-  static bool eval(unsigned long int l, mpf_srcptr f)
-  { return mpf_cmp_ui(f, l) < 0; }
-  static bool eval(mpf_srcptr f, signed long int l)
-  { return mpf_cmp_si(f, l) > 0; }
-  static bool eval(signed long int l, mpf_srcptr f)
-  { return mpf_cmp_si(f, l) < 0; }
-  static bool eval(mpf_srcptr f, double d)
-  { return mpf_cmp_d(f, d) > 0; }
-  static bool eval(double d, mpf_srcptr f)
-  { return mpf_cmp_d(f, d) < 0; }
+  template <class T, class U>
+  static inline bool eval(T t, U u) { return __gmp_binary_less::eval(u, t); }
 };
 
 struct __gmp_unary_increment


More information about the gmp-commit mailing list