[Gmp-commit] /var/hg/gmp: Prepare for expressions like factorial(int).

mercurial at gmplib.org mercurial at gmplib.org
Sat Dec 27 17:18:01 UTC 2014


details:   /var/hg/gmp/rev/2a19aef68f68
changeset: 16545:2a19aef68f68
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Sat Dec 27 18:17:58 2014 +0100
description:
Prepare for expressions like factorial(int).

diffstat:

 ChangeLog |   6 ++++++
 gmpxx.h   |  22 ++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diffs (59 lines):

diff -r d38720832028 -r 2a19aef68f68 ChangeLog
--- a/ChangeLog	Fri Dec 26 19:08:21 2014 +0100
+++ b/ChangeLog	Sat Dec 27 18:17:58 2014 +0100
@@ -1,3 +1,9 @@
+2014-12-27  Marc Glisse  <marc.glisse at inria.fr>
+
+	* gmpxx.h (__gmp_unary_expr): Use __gmp_resolve_ref.
+	(__gmp_expr): New specialization for unary expressions with
+	a builtin argument.
+
 2014-12-26  Marc Glisse  <marc.glisse at inria.fr>
 
 	* gmp-impl.h (tmp_debug_entry_t): Change block to type void*.
diff -r d38720832028 -r 2a19aef68f68 gmpxx.h
--- a/gmpxx.h	Fri Dec 26 19:08:21 2014 +0100
+++ b/gmpxx.h	Sat Dec 27 18:17:58 2014 +0100
@@ -1304,7 +1304,7 @@
 template <class T, class Op>
 struct __gmp_unary_expr
 {
-  const T &val;
+  typename __gmp_resolve_ref<T>::ref_type val;
 
   __gmp_unary_expr(const T &v) : val(v) { }
 private:
@@ -2148,6 +2148,24 @@
 };
 
 
+// simple expressions, U is a built-in numerical type
+
+template <class T, class U, class Op>
+class __gmp_expr<T, __gmp_unary_expr<U, Op> >
+{
+private:
+  typedef U val_type;
+
+  __gmp_unary_expr<val_type, Op> expr;
+public:
+  explicit __gmp_expr(const val_type &val) : expr(val) { }
+  void eval(typename __gmp_resolve_expr<T>::ptr_type p) const
+  { Op::eval(p, expr.val); }
+  const val_type & get_val() const { return expr.val; }
+  mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); }
+};
+
+
 // compound expressions
 
 template <class T, class U, class Op>
@@ -2203,7 +2221,7 @@
 };
 
 
-// simple expressions, T is a built-in numerical type
+// simple expressions, U is a built-in numerical type
 
 template <class T, class U, class Op>
 class __gmp_expr<T, __gmp_binary_expr<__gmp_expr<T, T>, U, Op> >


More information about the gmp-commit mailing list