diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2015-10-13 15:10:35 +0200 |
---|---|---|
committer | Marc Glisse <marc.glisse@inria.fr> | 2015-10-13 15:10:35 +0200 |
commit | 34cce9a7b17e7d52177eaefb63aea11a05ad9d20 (patch) | |
tree | d17530ed68183278fde927868b930e2651f6e913 /gmpxx.h | |
parent | 829126fa279eed0782ea8601e541d0d9728eb3b8 (diff) | |
download | gmp-34cce9a7b17e7d52177eaefb63aea11a05ad9d20.tar.gz |
Use the new mpq_cmp_z in gmpxx.h.
Diffstat (limited to 'gmpxx.h')
-rw-r--r-- | gmpxx.h | 144 |
1 files changed, 93 insertions, 51 deletions
@@ -858,6 +858,73 @@ struct __gmp_binary_xor { eval(z, w, d); } }; +struct __gmp_cmp_function +{ + static int eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w); } + + static int eval(mpz_srcptr z, unsigned long int l) + { return mpz_cmp_ui(z, l); } + static int eval(unsigned long int l, mpz_srcptr z) + { return -mpz_cmp_ui(z, l); } + static int eval(mpz_srcptr z, signed long int l) + { return mpz_cmp_si(z, l); } + static int eval(signed long int l, mpz_srcptr z) + { return -mpz_cmp_si(z, l); } + static int eval(mpz_srcptr z, double d) + { return mpz_cmp_d(z, d); } + static int eval(double d, mpz_srcptr z) + { return -mpz_cmp_d(z, d); } + + static int eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r); } + + static int eval(mpq_srcptr q, unsigned long int l) + { return mpq_cmp_ui(q, l, 1); } + static int eval(unsigned long int l, mpq_srcptr q) + { return -mpq_cmp_ui(q, l, 1); } + static int eval(mpq_srcptr q, signed long int l) + { return mpq_cmp_si(q, l, 1); } + static int eval(signed long int l, mpq_srcptr q) + { return -mpq_cmp_si(q, l, 1); } + static int eval(mpq_srcptr q, double d) + { __GMPXX_TMPQ_D; return mpq_cmp (q, temp); } + static int eval(double d, mpq_srcptr q) + { __GMPXX_TMPQ_D; return mpq_cmp (temp, q); } + static int eval(mpq_srcptr q, mpz_srcptr z) + { return mpq_cmp_z(q, z); } + static int eval(mpz_srcptr z, mpq_srcptr q) + { return -mpq_cmp_z(q, z); } + + static int eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g); } + + static int eval(mpf_srcptr f, unsigned long int l) + { return mpf_cmp_ui(f, l); } + static int eval(unsigned long int l, mpf_srcptr f) + { return -mpf_cmp_ui(f, l); } + static int eval(mpf_srcptr f, signed long int l) + { return mpf_cmp_si(f, l); } + static int eval(signed long int l, mpf_srcptr f) + { return -mpf_cmp_si(f, l); } + static int eval(mpf_srcptr f, double d) + { return mpf_cmp_d(f, d); } + static int eval(double d, mpf_srcptr f) + { return -mpf_cmp_d(f, d); } + static int eval(mpf_srcptr f, mpz_srcptr z) + { return mpf_cmp_z(f, z); } + static int eval(mpz_srcptr z, mpf_srcptr f) + { return -mpf_cmp_z(f, z); } + static int eval(mpf_srcptr f, mpq_srcptr q) + { + mpf_t qf; + mpf_init(qf); /* Should we use the precision of f? */ + mpf_set_q(qf, q); + int ret = eval(f, qf); + mpf_clear(qf); + return ret; + } + static int eval(mpq_srcptr q, mpf_srcptr f) + { return -eval(f, q); } +}; + struct __gmp_binary_equal { static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) == 0; } @@ -890,6 +957,10 @@ struct __gmp_binary_equal { __GMPXX_TMPQ_D; return mpq_equal (q, temp) != 0; } static bool eval(double d, mpq_srcptr q) { return eval(q, d); } + static bool eval(mpq_srcptr q, mpz_srcptr z) + { return mpq_cmp_z(q, z) == 0; } + static bool eval(mpz_srcptr z, mpq_srcptr q) + { return eval(q, z); } static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) == 0; } @@ -905,6 +976,14 @@ struct __gmp_binary_equal { return mpf_cmp_d(f, d) == 0; } static bool eval(double d, mpf_srcptr f) { return eval(f, d); } + static bool eval(mpf_srcptr f, mpz_srcptr z) + { return mpf_cmp_z(f, z) == 0; } + static bool eval(mpz_srcptr z, mpf_srcptr f) + { return eval(f, z); } + static bool eval(mpf_srcptr f, mpq_srcptr q) + { return __gmp_cmp_function::eval(f, q) == 0; } + static bool eval(mpq_srcptr q, mpf_srcptr f) + { return eval(f, q); } }; struct __gmp_binary_less @@ -938,6 +1017,10 @@ struct __gmp_binary_less { __GMPXX_TMPQ_D; return mpq_cmp (q, temp) < 0; } static bool eval(double d, mpq_srcptr q) { __GMPXX_TMPQ_D; return mpq_cmp (temp, q) < 0; } + static bool eval(mpq_srcptr q, mpz_srcptr z) + { return mpq_cmp_z(q, z) < 0; } + static bool eval(mpz_srcptr z, mpq_srcptr q) + { return mpq_cmp_z(q, z) > 0; } static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) < 0; } @@ -953,6 +1036,14 @@ struct __gmp_binary_less { return mpf_cmp_d(f, d) < 0; } static bool eval(double d, mpf_srcptr f) { return mpf_cmp_d(f, d) > 0; } + static bool eval(mpf_srcptr f, mpz_srcptr z) + { return mpf_cmp_z(f, z) < 0; } + static bool eval(mpz_srcptr z, mpf_srcptr f) + { return mpf_cmp_z(f, z) > 0; } + static bool eval(mpf_srcptr f, mpq_srcptr q) + { return __gmp_cmp_function::eval(f, q) < 0; } + static bool eval(mpq_srcptr q, mpf_srcptr f) + { return __gmp_cmp_function::eval(q, f) < 0; } }; struct __gmp_binary_greater @@ -1057,54 +1148,6 @@ struct __gmp_sgn_function static int eval(mpf_srcptr f) { return mpf_sgn(f); } }; -struct __gmp_cmp_function -{ - static int eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w); } - - static int eval(mpz_srcptr z, unsigned long int l) - { return mpz_cmp_ui(z, l); } - static int eval(unsigned long int l, mpz_srcptr z) - { return -mpz_cmp_ui(z, l); } - static int eval(mpz_srcptr z, signed long int l) - { return mpz_cmp_si(z, l); } - static int eval(signed long int l, mpz_srcptr z) - { return -mpz_cmp_si(z, l); } - static int eval(mpz_srcptr z, double d) - { return mpz_cmp_d(z, d); } - static int eval(double d, mpz_srcptr z) - { return -mpz_cmp_d(z, d); } - - static int eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r); } - - static int eval(mpq_srcptr q, unsigned long int l) - { return mpq_cmp_ui(q, l, 1); } - static int eval(unsigned long int l, mpq_srcptr q) - { return -mpq_cmp_ui(q, l, 1); } - static int eval(mpq_srcptr q, signed long int l) - { return mpq_cmp_si(q, l, 1); } - static int eval(signed long int l, mpq_srcptr q) - { return -mpq_cmp_si(q, l, 1); } - static int eval(mpq_srcptr q, double d) - { __GMPXX_TMPQ_D; return mpq_cmp (q, temp); } - static int eval(double d, mpq_srcptr q) - { __GMPXX_TMPQ_D; return mpq_cmp (temp, q); } - - static int eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g); } - - static int eval(mpf_srcptr f, unsigned long int l) - { return mpf_cmp_ui(f, l); } - static int eval(unsigned long int l, mpf_srcptr f) - { return -mpf_cmp_ui(f, l); } - static int eval(mpf_srcptr f, signed long int l) - { return mpf_cmp_si(f, l); } - static int eval(signed long int l, mpf_srcptr f) - { return -mpf_cmp_si(f, l); } - static int eval(mpf_srcptr f, double d) - { return mpf_cmp_d(f, d); } - static int eval(double d, mpf_srcptr f) - { return -mpf_cmp_d(f, d); } -}; - struct __gmp_gcd_function { static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) @@ -2840,9 +2883,8 @@ template <class T, class U, class V, class W> \ inline type fun(const __gmp_expr<T, U> &expr1, \ const __gmp_expr<V, W> &expr2) \ { \ - typedef typename __gmp_resolve_expr<T, V>::value_type eval_type; \ - __gmp_expr<eval_type, eval_type> const& temp1(expr1); \ - __gmp_expr<eval_type, eval_type> const& temp2(expr2); \ + __gmp_expr<T, T> const& temp1(expr1); \ + __gmp_expr<V, V> const& temp2(expr2); \ return eval_fun::eval(temp1.__get_mp(), temp2.__get_mp()); \ } |