Author: Amaury Forgeot d'Arc <[email protected]>
Branch: decimal-libmpdec
Changeset: r73812:7fc8de349403
Date: 2014-10-02 19:27 +0200
http://bitbucket.org/pypy/pypy/changeset/7fc8de349403/

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
@@ -273,10 +273,29 @@
                         interp_signals.flags_as_list(space, self.ctx.c_traps),
                         ])])
 
+    def number_class_w(self, space, w_v):
+        from pypy.module._decimal import interp_decimal
+        w_a = interp_decimal.convert_op_raise(space, self, w_v)
+        cp = rmpdec.mpd_class(w_a.mpd, self.ctx)
+        return space.wrap(rffi.charp2str(cp))
+
+    def to_eng_string_w(self, space, w_v):
+        from pypy.module._decimal import interp_decimal
+        w_a = interp_decimal.convert_op_raise(space, self, w_v)
+        return w_a.to_eng_string_w(space, self)
+
     def divmod_w(self, space, w_x, w_y):
         from pypy.module._decimal import interp_decimal
         return interp_decimal.W_Decimal.divmod_impl(space, self, w_x, w_y)
 
+    def copy_sign_w(self, space, w_v, w_w):
+        from pypy.module._decimal import interp_decimal
+        w_a, w_b = interp_decimal.convert_binop_raise(space, self, w_v, w_w)
+        w_result = interp_decimal.W_Decimal.allocate(space)
+        with self.catch_status(space) as (ctx, status_ptr):
+            rmpdec.mpd_qcopy_sign(w_result.mpd, w_a.mpd, w_b.mpd, status_ptr)
+        return w_result
+
     def same_quantum_w(self, space, w_v, w_w):
         from pypy.module._decimal import interp_decimal
         w_a, w_b = interp_decimal.convert_binop_raise(space, self, w_v, w_w)
@@ -325,6 +344,19 @@
             rmpdec.mpd_qcopy_abs(w_result.mpd, w_a.mpd, status_ptr)
         return w_result
 
+    def copy_decimal_w(self, space, w_v):
+        from pypy.module._decimal import interp_decimal
+        w_a = interp_decimal.convert_op_raise(space, self, w_v)
+        return w_a
+
+    def copy_negate_w(self, space, w_v):
+        from pypy.module._decimal import interp_decimal
+        w_a = interp_decimal.convert_op_raise(space, self, w_v)
+        w_result = interp_decimal.W_Decimal.allocate(space)
+        with self.catch_status(space) as (ctx, status_ptr):
+            rmpdec.mpd_qcopy_negate(w_result.mpd, w_a.mpd, status_ptr)
+        return w_result
+
 def descr_new_context(space, w_subtype, __args__):
     w_result = space.allocate_instance(W_Context, w_subtype)
     W_Context.__init__(w_result, space)
@@ -428,7 +460,10 @@
     to_integral_exact=make_unary_method('mpd_qround_to_intx'),
     to_integral_value=make_unary_method('mpd_qround_to_int', tag='value'),
     sqrt=make_unary_method('mpd_qsqrt'),
+    logb=make_unary_method('mpd_qlogb'),
     logical_invert=make_unary_method('mpd_qinvert'),
+    number_class=interp2app(W_Context.number_class_w),
+    to_eng_string=interp2app(W_Context.to_eng_string_w),
     # Binary Operations
     add=make_binary_method('mpd_qadd'),
     subtract=make_binary_method('mpd_qsub'),
@@ -446,10 +481,14 @@
     quantize=make_binary_method('mpd_qquantize'),
     remainder=make_binary_method('mpd_qrem'),
     remainder_near=make_binary_method('mpd_qrem_near'),
+    copy_sign = interp2app(W_Context.copy_sign_w),
     logical_and=make_binary_method('mpd_qand'),
     logical_or=make_binary_method('mpd_qor'),
     logical_xor=make_binary_method('mpd_qxor'),
+    rotate=make_binary_method('mpd_qrotate'),
     same_quantum = interp2app(W_Context.same_quantum_w),
+    scaleb=make_binary_method('mpd_qscaleb'),
+    shift=make_binary_method('mpd_qshift'),
     # Ternary operations
     power=interp2app(W_Context.power_w),
     fma=interp2app(W_Context.fma_w),
@@ -467,6 +506,8 @@
     _apply=interp2app(W_Context.apply_w),
     apply=interp2app(W_Context.apply_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),
     # Functions with two decimal arguments
     compare_total = make_binary_method_noctx('mpd_compare_total'),
     compare_total_mag = make_binary_method_noctx('mpd_compare_total_mag'),
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,13 @@
         context = interp_context.getcontext(space)
         return decimal_from_decimal(space, None, self, context, exact=True)
 
+    def adjusted_w(self, space):
+        if rmpdec.mpd_isspecial(self.mpd):
+            ret = 0
+        else:
+            ret = rmpdec.mpd_adjexp(self.mpd)
+        return space.wrap(ret)
+
     def as_tuple_w(self, space):
         "Return the DecimalTuple representation of a Decimal"
         w_sign = space.wrap(rmpdec.mpd_sign(self.mpd))
@@ -1216,6 +1223,7 @@
     is_normal = interp2app(W_Decimal.is_normal_w),
     is_subnormal = interp2app(W_Decimal.is_subnormal_w),
     # Unary functions, no context arg
+    adjusted = interp2app(W_Decimal.adjusted_w),
     conjugate = interp2app(W_Decimal.conjugate_w),
     # Binary functions, optional context arg for conversion errors
     compare_total = make_binary_method_noctx('mpd_compare_total'),
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_class", "mpd_same_quantum", "mpd_adjexp",
         "mpd_getprec", "mpd_getemin",  "mpd_getemax", "mpd_getround", 
"mpd_getclamp",
         "mpd_qsetprec", "mpd_qsetemin",  "mpd_qsetemax", "mpd_qsetround", 
"mpd_qsetclamp",
         "mpd_maxcontext",
@@ -205,6 +205,8 @@
     'mpd_class', [MPD_PTR, MPD_CONTEXT_PTR], rffi.CCHARP)
 mpd_same_quantum = external(
     'mpd_same_quantum', [MPD_PTR, MPD_PTR], rffi.INT)
+mpd_adjexp = external(
+    'mpd_adjexp', [MPD_PTR], rffi.SSIZE_T)
 
 # Context operations
 mpd_getprec = external(
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to