[pypy-commit] pypy default: test and fix reciprocal overflow return values

bdkearns noreply at buildbot.pypy.org
Tue Feb 26 09:19:13 CET 2013


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r61814:22d315119b14
Date: 2013-02-26 02:41 -0500
http://bitbucket.org/pypy/pypy/changeset/22d315119b14/

Log:	test and fix reciprocal overflow return values

diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -299,6 +299,19 @@
         for i in range(4):
             assert b[i] == reference[i]
 
+        for dtype in ['int8', 'int16', 'int32', 'int64',
+                      'uint8', 'uint16', 'uint32', 'uint64']:
+            reference = [0, -1, 0, 1, 0]
+            if dtype[0] == 'u':
+                reference[1] = 0
+            elif dtype == 'int32':
+                    reference[2] = -2147483648
+            elif dtype == 'int64':
+                    reference[2] = -9223372036854775808
+            a = array([-2, -1, 0, 1, 2], dtype)
+            b = reciprocal(a)
+            assert (b == reference).all()
+
     def test_subtract(self):
         from numpypy import array, subtract
 
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -7,11 +7,11 @@
 from pypy.objspace.std.floatobject import float2string
 from pypy.objspace.std.complexobject import str_format
 from rpython.rlib import rfloat, clibffi, rcomplex
-from rpython.rlib.rarithmetic import maxint
 from rpython.rlib.rawstorage import (alloc_raw_storage, raw_storage_setitem,
                                   raw_storage_getitem)
 from rpython.rlib.objectmodel import specialize
-from rpython.rlib.rarithmetic import widen, byteswap, r_ulonglong
+from rpython.rlib.rarithmetic import (widen, byteswap, r_ulonglong,
+                                      most_neg_value_of)
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rlib.rstruct.runpack import runpack
 from rpython.rlib.rstruct.nativefmttable import native_is_bigendian
@@ -506,7 +506,9 @@
     def reciprocal(self, v):
         if v == 0:
             # XXX good place to warn
-            return -maxint
+            if self.T in (rffi.INT, rffi.LONG):
+                return most_neg_value_of(self.T)
+            return 0
         if v == 1 or v == -1:
             return v
         return 0


More information about the pypy-commit mailing list