Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r78504:8310cf810f40
Date: 2015-07-09 10:41 +0200
http://bitbucket.org/pypy/pypy/changeset/8310cf810f40/

Log:    merge heads

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
@@ -540,6 +540,15 @@
         for v in [float('inf'), float('-inf'), float('nan'), float('-nan')]:
             assert math.isnan(fmod(v, 2))
 
+    def test_mod(self):
+        from numpy import mod
+        assert mod(5, 3) == 2
+        assert mod(5, -3) == -1
+        assert mod(-5, 3) == 1
+        assert mod(-5, -3) == -2
+        assert mod(2.5, 1) == 0.5
+        assert mod(-1.5, 2) == 0.5
+
     def test_minimum(self):
         from numpy import array, minimum, nan, isnan
 
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
@@ -759,7 +759,21 @@
 
     @simple_binary_op
     def mod(self, v1, v2):
-        return math.fmod(v1, v2)
+        # partial copy of pypy.objspace.std.floatobject.W_FloatObject.descr_mod
+        if v2 == 0.0:
+            return rfloat.NAN
+        mod = math.fmod(v1, v2)
+        if mod:
+            # ensure the remainder has the same sign as the denominator
+            if (v2 < 0.0) != (mod < 0.0):
+                mod += v2
+        else:
+            # the remainder is zero, and in the presence of signed zeroes
+            # fmod returns different results across platforms; ensure
+            # it has the same sign as the denominator; we'd like to do
+            # "mod = v2 * 0.0", but that may get optimized away
+            mod = rfloat.copysign(0.0, v2)
+        return mod
 
     @simple_binary_op
     def pow(self, v1, v2):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to