1. Branan Purvine-Riley
  2. pypy

Commits

Antonio Cuni  committed 404b108

implement math.copysign for the cli backend

  • Participants
  • Parent commits aac08fe
  • Branches ootype-virtualrefs

Comments (0)

Files changed (2)

File pypy/rpython/test/test_rfloat.py

View file
  • Ignore whitespace
                 return x
         self.interpret(fn, [1.0, 2.0, 3.0])
 
+    def test_copysign(self):
+        import math
+        def fn(x, y):
+            return math.copysign(x, y)
+        assert self.interpret(fn, [42, -1]) == -42
+        assert self.interpret(fn, [42, -0.0]) == -42
+        assert self.interpret(fn, [42, 0.0]) == 42
+        
 class TestLLtype(BaseTestRfloat, LLRtypeMixin):
 
     def test_hash(self):

File pypy/translator/cli/src/ll_math.cs

View file
  • Ignore whitespace
         {
             return Math.Tanh(x);
         }
+
+        static public double ll_math_copysign(double x, double y)
+        {
+            if (x < 0.0)
+                x = -x;
+            if (y > 0.0 || (y == 0.0 && Math.Atan2(y, -1.0) > 0.0))
+                return x;
+            else
+                return -x;
+        }
     }
 }