[pypy-commit] pypy decimal-libmpdec: More methods

amauryfa noreply at buildbot.pypy.org
Sun Oct 5 20:23:21 CEST 2014


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: decimal-libmpdec
Changeset: r73814:5a97de386f52
Date: 2014-10-04 21:23 +0200
http://bitbucket.org/pypy/pypy/changeset/5a97de386f52/

Log:	More methods

diff --git a/pypy/module/_decimal/interp_context.py b/pypy/module/_decimal/interp_context.py
--- a/pypy/module/_decimal/interp_context.py
+++ b/pypy/module/_decimal/interp_context.py
@@ -307,6 +307,17 @@
         result = rmpdec.mpd_same_quantum(w_a.mpd, w_b.mpd)
         return space.wrap(bool(result))
 
+    def etiny_w(self, space):
+        return space.wrap(rmpdec.mpd_etiny(self.ctx))
+
+    def etop_w(self, space):
+        return space.wrap(rmpdec.mpd_etop(self.ctx))
+
+    def radix_w(self, space):
+        from pypy.module._decimal import interp_decimal
+        return interp_decimal.decimal_from_ssize(
+            space, None, 10, self, exact=True)
+
     # Ternary operations
     def power_w(self, space, w_a, w_b, w_modulo=None):
         from pypy.module._decimal import interp_decimal
@@ -341,6 +352,12 @@
         w_a = interp_decimal.convert_op_raise(space, self, w_v)
         return w_a.apply(space, self)
 
+    def canonical_w(self, space, w_v):
+        from pypy.module._decimal import interp_decimal
+        # Just check the type
+        space.interp_w(interp_decimal.W_Decimal, w_v)
+        return w_v
+
     def copy_abs_w(self, space, w_v):
         from pypy.module._decimal import interp_decimal
         w_a = interp_decimal.convert_op_raise(space, self, w_v)
@@ -498,6 +515,10 @@
     # Ternary operations
     power=interp2app(W_Context.power_w),
     fma=interp2app(W_Context.fma_w),
+    # No argument
+    Etiny=interp2app(W_Context.etiny_w),
+    Etop=interp2app(W_Context.etop_w),
+    radix=interp2app(W_Context.radix_w),
     # Boolean operations
     is_signed=make_bool_method_noctx('mpd_issigned'),
     is_zero=make_bool_method_noctx('mpd_iszero'),
@@ -511,6 +532,7 @@
     # Functions with a single decimal argument
     _apply=interp2app(W_Context.apply_w),
     apply=interp2app(W_Context.apply_w),
+    canonical=interp2app(W_Context.canonical_w),
     copy_abs=interp2app(W_Context.copy_abs_w),
     copy_decimal=interp2app(W_Context.copy_decimal_w),
     copy_negate=interp2app(W_Context.copy_negate_w),
diff --git a/pypy/module/_decimal/interp_decimal.py b/pypy/module/_decimal/interp_decimal.py
--- a/pypy/module/_decimal/interp_decimal.py
+++ b/pypy/module/_decimal/interp_decimal.py
@@ -606,6 +606,10 @@
         context = interp_context.getcontext(space)
         return decimal_from_decimal(space, None, self, context, exact=True)
 
+    def radix_w(self, space):
+        context = interp_context.getcontext(space)
+        return decimal_from_ssize(space, None, 10, context, exact=True)
+
     def adjusted_w(self, space):
         if rmpdec.mpd_isspecial(self.mpd):
             ret = 0
@@ -1225,6 +1229,7 @@
     # Unary functions, no context arg
     adjusted = interp2app(W_Decimal.adjusted_w),
     conjugate = interp2app(W_Decimal.conjugate_w),
+    radix = interp2app(W_Decimal.radix_w),
     # Binary functions, optional context arg for conversion errors
     compare_total = make_binary_method_noctx('mpd_compare_total'),
     compare_total_mag = make_binary_method_noctx('mpd_compare_total_mag'),
diff --git a/rpython/rlib/rmpdec.py b/rpython/rlib/rmpdec.py
--- a/rpython/rlib/rmpdec.py
+++ b/rpython/rlib/rmpdec.py
@@ -41,7 +41,7 @@
         "mpd_qcopy", "mpd_qncopy", "mpd_setspecial", "mpd_clear_flags",
         "mpd_qimport_u32", "mpd_qexport_u32", "mpd_qexport_u16",
         "mpd_set_sign", "mpd_set_positive", "mpd_sign", "mpd_qfinalize",
-        "mpd_class", "mpd_same_quantum", "mpd_adjexp",
+        "mpd_class", "mpd_same_quantum", "mpd_adjexp", "mpd_etiny", "mpd_etop",
         "mpd_getprec", "mpd_getemin",  "mpd_getemax", "mpd_getround", "mpd_getclamp",
         "mpd_qsetprec", "mpd_qsetemin",  "mpd_qsetemax", "mpd_qsetround", "mpd_qsetclamp",
         "mpd_maxcontext",
@@ -207,6 +207,10 @@
     'mpd_same_quantum', [MPD_PTR, MPD_PTR], rffi.INT)
 mpd_adjexp = external(
     'mpd_adjexp', [MPD_PTR], rffi.SSIZE_T)
+mpd_etiny = external(
+    'mpd_etiny', [MPD_CONTEXT_PTR], rffi.SSIZE_T)
+mpd_etop = external(
+    'mpd_etop', [MPD_CONTEXT_PTR], rffi.SSIZE_T)
 
 # Context operations
 mpd_getprec = external(


More information about the pypy-commit mailing list