[Gmp-commit] /var/hg/gmp: Dedup the comparison code.

mercurial at gmplib.org mercurial at gmplib.org
Sun Mar 20 21:39:32 CET 2011


details:   /var/hg/gmp/rev/74d530bb1db8
changeset: 14074:74d530bb1db8
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Sun Mar 20 21:39:22 2011 +0100
description:
Dedup the comparison code.

diffstat:

 ChangeLog           |    7 +
 gmpxx.h             |  200 +---------------------------------------------------
 tests/cxx/t-ops2.cc |    8 +-
 3 files changed, 14 insertions(+), 201 deletions(-)

diffs (282 lines):

diff -r 73696857a067 -r 74d530bb1db8 ChangeLog
--- a/ChangeLog	Sun Mar 20 20:23:07 2011 +0100
+++ b/ChangeLog	Sun Mar 20 21:39:22 2011 +0100
@@ -1,3 +1,10 @@
+2011-03-16  Marc Glisse  <marc.glisse at inria.fr>
+
+	* gmpxx.h (__gmp_binary_not_equal): Remove, use !__gmp_binary_equal.
+	(__gmp_binary_less_equal): Remove, use !__gmp_binary_greater.
+	(__gmp_binary_greater_equal): Remove, use !__gmp_binary_less.
+	* tests/cxx/t-ops2.cc: Typo.
+
 2011-03-20  Niels Möller  <nisse at lysator.liu.se>
 
 	* tune/common.c (speed_mpn_div_qr_2_norm): New function.
diff -r 73696857a067 -r 74d530bb1db8 gmpxx.h
--- a/gmpxx.h	Sun Mar 20 20:23:07 2011 +0100
+++ b/gmpxx.h	Sun Mar 20 21:39:22 2011 +0100
@@ -765,71 +765,6 @@
   { return mpf_cmp_d(f, d) == 0; }
 };
 
-struct __gmp_binary_not_equal
-{
-  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_equal(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_equal(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_equal(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; }
-};
-
 struct __gmp_binary_less
 {
   static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) < 0; }
@@ -894,70 +829,6 @@
   { return mpf_cmp_d(f, d) > 0; }
 };
 
-struct __gmp_binary_less_equal
-{
-  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; }
-};
-
 struct __gmp_binary_greater
 {
   static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) > 0; }
@@ -1022,70 +893,6 @@
   { return mpf_cmp_d(f, d) < 0; }
 };
 
-struct __gmp_binary_greater_equal
-{
-  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; }
-};
-
 struct __gmp_unary_increment
 {
   static void eval(mpz_ptr z) { mpz_add_ui(z, z, 1); }
@@ -3075,12 +2882,11 @@
 __GMP_DEFINE_BINARY_FUNCTION_UI(operator>>, __gmp_binary_rshift)
 
 __GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator==, __gmp_binary_equal)
-__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator!=, __gmp_binary_not_equal)
+__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator!=, ! __gmp_binary_equal)
 __GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator<, __gmp_binary_less)
-__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator<=, __gmp_binary_less_equal)
+__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator<=, ! __gmp_binary_greater)
 __GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator>, __gmp_binary_greater)
-__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator>=, \
-                                  __gmp_binary_greater_equal)
+__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator>=, ! __gmp_binary_less)
 
 __GMP_DEFINE_UNARY_FUNCTION(abs, __gmp_abs_function)
 __GMP_DEFINE_UNARY_FUNCTION(trunc, __gmp_trunc_function)
diff -r 73696857a067 -r 74d530bb1db8 tests/cxx/t-ops2.cc
--- a/tests/cxx/t-ops2.cc	Sun Mar 20 20:23:07 2011 +0100
+++ b/tests/cxx/t-ops2.cc	Sun Mar 20 21:39:22 2011 +0100
@@ -142,13 +142,13 @@
   CHECK_MPZ(T,5,-2,<); 
   CHECK_MPZ(T,5,-2,>); 
   CHECK_MPZ(T,5,-2,<=);
-  CHECK_MPZ(T,5,-2,<=);
+  CHECK_MPZ(T,5,-2,>=);
   CHECK_MPZ(T,5,-2,==);
   CHECK_MPZ(T,5,-2,!=);
   CHECK_MPZ(T,0,0,<);  
   CHECK_MPZ(T,0,0,>);  
   CHECK_MPZ(T,0,0,<=); 
-  CHECK_MPZ(T,0,0,<=); 
+  CHECK_MPZ(T,0,0,>=); 
   CHECK_MPZ(T,0,0,==); 
   CHECK_MPZ(T,0,0,!=); 
   ASSERT_ALWAYS(T(6)<<2==6.*4);
@@ -211,13 +211,13 @@
   CHECK_MPQ(mpf_class,5,-2,<);  
   CHECK_MPQ(mpf_class,5,-2,>);  
   CHECK_MPQ(mpf_class,5,-2,<=); 
-  CHECK_MPQ(mpf_class,5,-2,<=); 
+  CHECK_MPQ(mpf_class,5,-2,>=); 
   CHECK_MPQ(mpf_class,5,-2,==); 
   CHECK_MPQ(mpf_class,5,-2,!=); 
   CHECK_MPQ(mpf_class,0,0,<);  
   CHECK_MPQ(mpf_class,0,0,>);  
   CHECK_MPQ(mpf_class,0,0,<=); 
-  CHECK_MPQ(mpf_class,0,0,<=); 
+  CHECK_MPQ(mpf_class,0,0,>=); 
   CHECK_MPQ(mpf_class,0,0,==); 
   CHECK_MPQ(mpf_class,0,0,!=); 
 }


More information about the gmp-commit mailing list