Author: Amaury Forgeot d'Arc <[email protected]>
Branch: decimal-libmpdec
Changeset: r73811:95ba229db13d
Date: 2014-10-01 19:23 +0200
http://bitbucket.org/pypy/pypy/changeset/95ba229db13d/

Log:    add Decimal.same_quantum

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
@@ -277,6 +277,12 @@
         from pypy.module._decimal import interp_decimal
         return interp_decimal.W_Decimal.divmod_impl(space, self, w_x, w_y)
 
+    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)
+        result = rmpdec.mpd_same_quantum(w_a.mpd, w_b.mpd)
+        return space.wrap(bool(result))
+
     # Ternary operations
     def power_w(self, space, w_a, w_b, w_modulo=None):
         from pypy.module._decimal import interp_decimal
@@ -443,6 +449,7 @@
     logical_and=make_binary_method('mpd_qand'),
     logical_or=make_binary_method('mpd_qor'),
     logical_xor=make_binary_method('mpd_qxor'),
+    same_quantum = interp2app(W_Context.same_quantum_w),
     # Ternary operations
     power=interp2app(W_Context.power_w),
     fma=interp2app(W_Context.fma_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
@@ -495,13 +495,19 @@
 
     def copy_sign_w(self, space, w_other, w_context=None):
         context = convert_context(space, w_context)
-        w_other = convert_op_raise(space, context, w_other)
+        w_a, w_b = convert_binop_raise(space, context, self, w_other)
         w_result = W_Decimal.allocate(space)
         with context.catch_status(space) as (ctx, status_ptr):
-            rmpdec.mpd_qcopy_sign(w_result.mpd, self.mpd, w_other.mpd,
+            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_other, w_context=None):
+        context = convert_context(space, w_context)
+        w_a, w_b = convert_binop_raise(space, context, self, w_other)
+        result = rmpdec.mpd_same_quantum(w_a.mpd, w_b.mpd)
+        return space.wrap(bool(result))
+
     # Unary arithmetic functions, optional context arg
 
     def number_class_w(self, space, w_context=None):
@@ -1215,6 +1221,7 @@
     compare_total = make_binary_method_noctx('mpd_compare_total'),
     compare_total_mag = make_binary_method_noctx('mpd_compare_total_mag'),
     copy_sign = interp2app(W_Decimal.copy_sign_w),
+    same_quantum = interp2app(W_Decimal.same_quantum_w),
     #
     as_tuple = interp2app(W_Decimal.as_tuple_w),
     from_float = interp2app(decimal_from_float_w, as_classmethod=True),
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_class", "mpd_same_quantum",
         "mpd_getprec", "mpd_getemin",  "mpd_getemax", "mpd_getround", 
"mpd_getclamp",
         "mpd_qsetprec", "mpd_qsetemin",  "mpd_qsetemax", "mpd_qsetround", 
"mpd_qsetclamp",
         "mpd_maxcontext",
@@ -203,6 +203,8 @@
     'mpd_qfinalize', [MPD_PTR, MPD_CONTEXT_PTR, rffi.UINTP], lltype.Void)
 mpd_class = external(
     'mpd_class', [MPD_PTR, MPD_CONTEXT_PTR], rffi.CCHARP)
+mpd_same_quantum = external(
+    'mpd_same_quantum', [MPD_PTR, MPD_PTR], rffi.INT)
 
 # Context operations
 mpd_getprec = external(
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to