Commits

Taavi Burns committed 19b12ba

Make tests more robust and use math.pow for logaddexp and logaddexp2

Comments (0)

Files changed (2)

pypy/module/micronumpy/test/test_ufuncs.py

         prob1 = math.log(1e-50)
         prob2 = math.log(2.5e-50)
         prob12 = logaddexp(prob1, prob2)
-        assert prob12 == -113.87649168120691
-        assert math.exp(prob12) == 3.5000000000000057e-50
+        assert math.fabs(-113.87649168120691 - prob12) < 0.000000000001
 
         assert logaddexp(0, 0) == math.log(2)
         assert logaddexp(float('-inf'), 0) == 0
         prob1 = math.log(1e-50) / log2
         prob2 = math.log(2.5e-50) / log2
         prob12 = logaddexp2(prob1, prob2)
-        assert prob12 == -164.28904982231052
+        assert math.fabs(-164.28904982231052 - prob12) < 0.000000000001
 
         assert logaddexp2(0, 0) == 1
         assert logaddexp2(float('-inf'), 0) == 0

pypy/module/micronumpy/types.py

     @simple_binary_op
     def logaddexp2(self, v1, v2):
         try:
-            v1e = 2**v1
+            v1e = math.pow(2, v1)
         except OverflowError:
             v1e = rfloat.INFINITY
         try:
-            v2e = 2**v2
+            v2e = math.pow(2, v2)
         except OverflowError:
             v2e = rfloat.INFINITY