Author: Benjamin Peterson <benja...@python.org>
Branch: 
Changeset: r93677:9a00e4a12145
Date: 2018-01-17 22:20 -0800
http://bitbucket.org/pypy/pypy/changeset/9a00e4a12145/

Log:    assume math.copysign and always use it over rfloat.copysign

diff --git a/pypy/interpreter/astcompiler/assemble.py 
b/pypy/interpreter/astcompiler/assemble.py
--- a/pypy/interpreter/astcompiler/assemble.py
+++ b/pypy/interpreter/astcompiler/assemble.py
@@ -1,7 +1,7 @@
 """Python control flow graph generation and bytecode assembly."""
 
+import math
 import os
-from rpython.rlib import rfloat
 from rpython.rlib.objectmodel import we_are_translated
 
 from pypy.interpreter.astcompiler import ast, misc, symtable
@@ -266,7 +266,7 @@
         w_type = space.type(obj)
         if space.is_w(w_type, space.w_float):
             val = space.float_w(obj)
-            if val == 0.0 and rfloat.copysign(1., val) < 0:
+            if val == 0.0 and math.copysign(1., val) < 0:
                 w_key = space.newtuple([obj, space.w_float, space.w_None])
             else:
                 w_key = space.newtuple([obj, space.w_float])
@@ -276,9 +276,9 @@
             real = space.float_w(w_real)
             imag = space.float_w(w_imag)
             real_negzero = (real == 0.0 and
-                            rfloat.copysign(1., real) < 0)
+                            math.copysign(1., real) < 0)
             imag_negzero = (imag == 0.0 and
-                            rfloat.copysign(1., imag) < 0)
+                            math.copysign(1., imag) < 0)
             if real_negzero and imag_negzero:
                 tup = [obj, space.w_complex, space.w_None, space.w_None,
                        space.w_None]
diff --git a/pypy/module/cmath/test/test_cmath.py 
b/pypy/module/cmath/test/test_cmath.py
--- a/pypy/module/cmath/test/test_cmath.py
+++ b/pypy/module/cmath/test/test_cmath.py
@@ -1,5 +1,5 @@
 from __future__ import with_statement
-from rpython.rlib.rfloat import copysign, isnan, isinf
+from rpython.rlib.rfloat import isnan, isinf
 from pypy.module.cmath import interp_cmath
 import os, sys, math
 
@@ -11,7 +11,7 @@
     assert isinstance(sqrt_special_values[5][1], tuple)
     assert sqrt_special_values[5][1][0] == 1e200 * 1e200
     assert sqrt_special_values[5][1][1] == -0.
-    assert copysign(1., sqrt_special_values[5][1][1]) == -1.
+    assert math.copysign(1., sqrt_special_values[5][1][1]) == -1.
 
 
 class AppTestCMath:
@@ -158,8 +158,7 @@
     # and b to have opposite signs; in practice these hardly ever
     # occur).
     if not a and not b:
-        # only check it if we are running on top of CPython >= 2.6
-        if sys.version_info >= (2, 6) and copysign(1., a) != copysign(1., b):
+        if math.copysign(1., a) != math.copysign(1., b):
             raise AssertionError(msg + 'zero has wrong sign: expected %r, '
                                        'got %r' % (a, b))
 
diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py
--- a/pypy/module/math/interp_math.py
+++ b/pypy/module/math/interp_math.py
@@ -61,7 +61,7 @@
     # No exceptions possible.
     x = _get_double(space, w_x)
     y = _get_double(space, w_y)
-    return space.newfloat(rfloat.copysign(x, y))
+    return space.newfloat(math.copysign(x, y))
 
 def isinf(space, w_x):
     """Return True if x is infinity."""
diff --git a/pypy/module/micronumpy/test/test_complex.py 
b/pypy/module/micronumpy/test/test_complex.py
--- a/pypy/module/micronumpy/test/test_complex.py
+++ b/pypy/module/micronumpy/test/test_complex.py
@@ -1,12 +1,13 @@
 from __future__ import with_statement
 
+import math
 import sys
 
 from pypy.conftest import option
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import interp2app
 from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
-from rpython.rlib.rfloat import isnan, isinf, copysign
+from rpython.rlib.rfloat import isnan, isinf
 from rpython.rlib.rcomplex import c_pow
 
 
@@ -37,8 +38,7 @@
     # and b to have opposite signs; in practice these hardly ever
     # occur).
     if not a and not b:
-        # only check it if we are running on top of CPython >= 2.6
-        if sys.version_info >= (2, 6) and copysign(1., a) != copysign(1., b):
+        if math.copysign(1., a) != math.copysign(1., b):
             raise AssertionError( msg + \
                     'zero has wrong sign: expected %r, got %r' % (a, b))
 
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
@@ -767,7 +767,7 @@
         except ZeroDivisionError:
             if v1 == v2 == 0.0:
                 return rfloat.NAN
-            return rfloat.copysign(rfloat.INFINITY, v1 * v2)
+            return math.copysign(rfloat.INFINITY, v1 * v2)
 
     @simple_binary_op
     def floordiv(self, v1, v2):
@@ -776,7 +776,7 @@
         except ZeroDivisionError:
             if v1 == v2 == 0.0:
                 return rfloat.NAN
-            return rfloat.copysign(rfloat.INFINITY, v1 * v2)
+            return math.copysign(rfloat.INFINITY, v1 * v2)
 
     @simple_binary_op
     def mod(self, v1, v2):
@@ -793,7 +793,7 @@
             # 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)
+            mod = math.copysign(0.0, v2)
         return mod
 
     @simple_binary_op
@@ -805,7 +805,7 @@
         except OverflowError:
             if math.modf(v2)[0] == 0 and math.modf(v2 / 2)[0] != 0:
                 # Odd integer powers result in the same sign as the base
-                return rfloat.copysign(rfloat.INFINITY, v1)
+                return math.copysign(rfloat.INFINITY, v1)
             return rfloat.INFINITY
 
     @simple_binary_op
@@ -818,11 +818,11 @@
             return 0.0
         if rfloat.isnan(v):
             return rfloat.NAN
-        return rfloat.copysign(1.0, v)
+        return math.copysign(1.0, v)
 
     @raw_unary_op
     def signbit(self, v):
-        return rfloat.copysign(1.0, v) < 0.0
+        return math.copysign(1.0, v) < 0.0
 
     @simple_unary_op
     def fabs(self, v):
@@ -862,7 +862,7 @@
     @simple_unary_op
     def reciprocal(self, v):
         if v == 0.0:
-            return rfloat.copysign(rfloat.INFINITY, v)
+            return math.copysign(rfloat.INFINITY, v)
         return 1.0 / v
 
     @simple_unary_op
@@ -1537,8 +1537,8 @@
         if rfloat.isinf(v[1]) and rfloat.isinf(v[0]):
             return rfloat.NAN, rfloat.NAN
         if rfloat.isinf(v[0]):
-            return (rfloat.copysign(0., v[0]),
-                    rfloat.copysign(0., -v[1]))
+            return (math.copysign(0., v[0]),
+                    math.copysign(0., -v[1]))
         a2 = v[0]*v[0] + v[1]*v[1]
         try:
             return rcomplex.c_div((v[0], -v[1]), (a2, 0.))
diff --git a/pypy/objspace/std/complexobject.py 
b/pypy/objspace/std/complexobject.py
--- a/pypy/objspace/std/complexobject.py
+++ b/pypy/objspace/std/complexobject.py
@@ -4,7 +4,7 @@
 from rpython.rlib.rarithmetic import intmask, r_ulonglong
 from rpython.rlib.rbigint import rbigint
 from rpython.rlib.rfloat import (
-    DTSF_STR_PRECISION, copysign, formatd, isinf, isnan, string_to_float)
+    DTSF_STR_PRECISION, formatd, isinf, isnan, string_to_float)
 from rpython.rlib.rstring import ParseStringError
 
 from pypy.interpreter.baseobjspace import W_Root
@@ -346,17 +346,17 @@
                                space.newfloat(self.imagval)])
 
     def descr_repr(self, space):
-        if self.realval == 0 and copysign(1., self.realval) == 1.:
+        if self.realval == 0 and math.copysign(1., self.realval) == 1.:
             return space.newtext(repr_format(self.imagval) + 'j')
-        sign = (copysign(1., self.imagval) == 1. or
+        sign = (math.copysign(1., self.imagval) == 1. or
                 isnan(self.imagval)) and '+' or ''
         return space.newtext('(' + repr_format(self.realval)
                              + sign + repr_format(self.imagval) + 'j)')
 
     def descr_str(self, space):
-        if self.realval == 0 and copysign(1., self.realval) == 1.:
+        if self.realval == 0 and math.copysign(1., self.realval) == 1.:
             return space.newtext(str_format(self.imagval) + 'j')
-        sign = (copysign(1., self.imagval) == 1. or
+        sign = (math.copysign(1., self.imagval) == 1. or
                 isnan(self.imagval)) and '+' or ''
         return space.newtext('(' + str_format(self.realval)
                              + sign + str_format(self.imagval) + 'j)')
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -7,7 +7,7 @@
 from rpython.rlib.rarithmetic import int_between
 from rpython.rlib.rbigint import rbigint
 from rpython.rlib.rfloat import (
-    DTSF_ADD_DOT_0, DTSF_STR_PRECISION, INFINITY, NAN, copysign,
+    DTSF_ADD_DOT_0, DTSF_STR_PRECISION, INFINITY, NAN,
     float_as_rbigint_ratio, formatd, isfinite, isinf, isnan)
 from rpython.rlib.rstring import ParseStringError
 from rpython.rlib.unroll import unrolling_iterable
@@ -533,7 +533,7 @@
             # fmod returns different results across platforms; ensure
             # it has the same sign as the denominator; we'd like to do
             # "mod = y * 0.0", but that may get optimized away
-            mod = copysign(0.0, y)
+            mod = math.copysign(0.0, y)
 
         return W_FloatObject(mod)
 
@@ -617,7 +617,7 @@
         if not isfinite(value):
             return self.descr_str(space)
         if value == 0.0:
-            if copysign(1., value) == -1.:
+            if math.copysign(1., value) == -1.:
                 return space.newtext("-0x0.0p+0")
             else:
                 return space.newtext("0x0.0p+0")
@@ -832,7 +832,7 @@
                 return abs(x)
         else:
             if y_is_odd:
-                return copysign(0.0, x)
+                return math.copysign(0.0, x)
             else:
                 return 0.0
 
diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py
--- a/pypy/objspace/std/newformat.py
+++ b/pypy/objspace/std/newformat.py
@@ -1,12 +1,13 @@
 """The unicode/str format() method"""
 
+import math
 import sys
 import string
 
 from pypy.interpreter.error import OperationError, oefmt
 from rpython.rlib import rstring, runicode, rlocale, rfloat, jit
 from rpython.rlib.objectmodel import specialize
-from rpython.rlib.rfloat import copysign, formatd
+from rpython.rlib.rfloat import formatd
 from rpython.rlib.rarithmetic import r_uint, intmask
 from pypy.interpreter.signature import Signature
 
@@ -1031,7 +1032,7 @@
                 default_precision = 12
                 #test if real part is non-zero
                 if (w_complex.realval == 0 and
-                    copysign(1., w_complex.realval) == 1.):
+                    math.copysign(1., w_complex.realval) == 1.):
                     skip_re = 1
                 else:
                     add_parens = 1
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -30,6 +30,7 @@
 from __future__ import absolute_import
 
 import inspect
+import math
 import weakref
 from types import BuiltinFunctionType, MethodType
 from collections import OrderedDict, defaultdict
@@ -169,13 +170,13 @@
     def __eq__(self, other):
         if (type(self) is SomeFloat and type(other) is SomeFloat and
             self.is_constant() and other.is_constant()):
-            from rpython.rlib.rfloat import isnan, copysign
+            from rpython.rlib.rfloat import isnan
             # NaN unpleasantness.
             if isnan(self.const) and isnan(other.const):
                 return True
             # 0.0 vs -0.0 unpleasantness.
             if not self.const and not other.const:
-                return copysign(1., self.const) == copysign(1., other.const)
+                return math.copysign(1., self.const) == math.copysign(1., 
other.const)
             #
         return super(SomeFloat, self).__eq__(other)
 
diff --git a/rpython/rlib/rcomplex.py b/rpython/rlib/rcomplex.py
--- a/rpython/rlib/rcomplex.py
+++ b/rpython/rlib/rcomplex.py
@@ -1,6 +1,6 @@
 import math
 from math import fabs
-from rpython.rlib.rfloat import copysign, asinh, log1p, isfinite, isinf, isnan
+from rpython.rlib.rfloat import asinh, log1p, isfinite, isinf, isnan
 from rpython.rlib.constant import DBL_MIN, CM_SCALE_UP, CM_SCALE_DOWN
 from rpython.rlib.constant import CM_LARGE_DOUBLE, DBL_MANT_DIG
 from rpython.rlib.constant import M_LN2, M_LN10
@@ -151,9 +151,9 @@
     d = ay/(2.*s)
 
     if x >= 0.:
-        return (s, copysign(d, y))
+        return (s, math.copysign(d, y))
     else:
-        return (d, copysign(s, y))
+        return (d, math.copysign(s, y))
 
 
 
@@ -167,10 +167,10 @@
         # split into cases to make sure that the branch cut has the
         # correct continuity on systems with unsigned zeros
         if x < 0.:
-            imag = -copysign(math.log(math.hypot(x/2., y/2.)) +
+            imag = -math.copysign(math.log(math.hypot(x/2., y/2.)) +
                              M_LN2*2., y)
         else:
-            imag = copysign(math.log(math.hypot(x/2., y/2.)) +
+            imag = math.copysign(math.log(math.hypot(x/2., y/2.)) +
                             M_LN2*2., -y)
     else:
         s1x, s1y = c_sqrt(1.-x, -y)
@@ -210,10 +210,10 @@
 
     if fabs(x) > CM_LARGE_DOUBLE or fabs(y) > CM_LARGE_DOUBLE:
         if y >= 0.:
-            real = copysign(math.log(math.hypot(x/2., y/2.)) +
+            real = math.copysign(math.log(math.hypot(x/2., y/2.)) +
                             M_LN2*2., x)
         else:
-            real = -copysign(math.log(math.hypot(x/2., y/2.)) +
+            real = -math.copysign(math.log(math.hypot(x/2., y/2.)) +
                              M_LN2*2., -x)
         imag = math.atan2(y, fabs(x))
     else:
@@ -249,7 +249,7 @@
         # except when working with unsigned zeros: they're there to
         # ensure that the branch cut has the correct continuity on
         # systems that don't support signed zeros
-        imag = -copysign(math.pi/2., -y)
+        imag = -math.copysign(math.pi/2., -y)
     elif x == 1. and ay < CM_SQRT_DBL_MIN:
         # C99 standard says:  atanh(1+/-0.) should be inf +/- 0i
         if ay == 0.:
@@ -258,7 +258,7 @@
             #imag = y
         else:
             real = -math.log(math.sqrt(ay)/math.sqrt(math.hypot(ay, 2.)))
-            imag = copysign(math.atan2(2., -ay) / 2, y)
+            imag = math.copysign(math.atan2(2., -ay) / 2, y)
     else:
         real = log1p(4.*x/((1-x)*(1-x) + ay*ay))/4.
         imag = -math.atan2(-2.*y, (1-x)*(1+x) - ay*ay) / 2.
@@ -332,11 +332,11 @@
     if not isfinite(x) or not isfinite(y):
         if isinf(x) and isfinite(y) and y != 0.:
             if x > 0:
-                real = copysign(INF, math.cos(y))
-                imag = copysign(INF, math.sin(y))
+                real = math.copysign(INF, math.cos(y))
+                imag = math.copysign(INF, math.sin(y))
             else:
-                real = copysign(0., math.cos(y))
-                imag = copysign(0., math.sin(y))
+                real = math.copysign(0., math.cos(y))
+                imag = math.copysign(0., math.sin(y))
             r = (real, imag)
         else:
             r = exp_special_values[special_type(x)][special_type(y)]
@@ -364,11 +364,11 @@
     if not isfinite(x) or not isfinite(y):
         if isinf(x) and isfinite(y) and y != 0.:
             if x > 0:
-                real = copysign(INF, math.cos(y))
-                imag = copysign(INF, math.sin(y))
+                real = math.copysign(INF, math.cos(y))
+                imag = math.copysign(INF, math.sin(y))
             else:
-                real = copysign(INF, math.cos(y))
-                imag = -copysign(INF, math.sin(y))
+                real = math.copysign(INF, math.cos(y))
+                imag = -math.copysign(INF, math.sin(y))
             r = (real, imag)
         else:
             r = cosh_special_values[special_type(x)][special_type(y)]
@@ -382,7 +382,7 @@
     if fabs(x) > CM_LOG_LARGE_DOUBLE:
         # deal correctly with cases where cosh(x) overflows but
         # cosh(z) does not.
-        x_minus_one = x - copysign(1., x)
+        x_minus_one = x - math.copysign(1., x)
         real = math.cos(y) * math.cosh(x_minus_one) * math.e
         imag = math.sin(y) * math.sinh(x_minus_one) * math.e
     else:
@@ -398,11 +398,11 @@
     if not isfinite(x) or not isfinite(y):
         if isinf(x) and isfinite(y) and y != 0.:
             if x > 0:
-                real = copysign(INF, math.cos(y))
-                imag = copysign(INF, math.sin(y))
+                real = math.copysign(INF, math.cos(y))
+                imag = math.copysign(INF, math.sin(y))
             else:
-                real = -copysign(INF, math.cos(y))
-                imag = copysign(INF, math.sin(y))
+                real = -math.copysign(INF, math.cos(y))
+                imag = math.copysign(INF, math.sin(y))
             r = (real, imag)
         else:
             r = sinh_special_values[special_type(x)][special_type(y)]
@@ -414,7 +414,7 @@
         return r
 
     if fabs(x) > CM_LOG_LARGE_DOUBLE:
-        x_minus_one = x - copysign(1., x)
+        x_minus_one = x - math.copysign(1., x)
         real = math.cos(y) * math.sinh(x_minus_one) * math.e
         imag = math.sin(y) * math.cosh(x_minus_one) * math.e
     else:
@@ -440,10 +440,10 @@
         if isinf(x) and isfinite(y) and y != 0.:
             if x > 0:
                 real = 1.0        # vv XXX why is the 2. there?
-                imag = copysign(0., 2. * math.sin(y) * math.cos(y))
+                imag = math.copysign(0., 2. * math.sin(y) * math.cos(y))
             else:
                 real = -1.0
-                imag = copysign(0., 2. * math.sin(y) * math.cos(y))
+                imag = math.copysign(0., 2. * math.sin(y) * math.cos(y))
             r = (real, imag)
         else:
             r = tanh_special_values[special_type(x)][special_type(y)]
@@ -454,7 +454,7 @@
         return r
 
     if fabs(x) > CM_LOG_LARGE_DOUBLE:
-        real = copysign(1., x)
+        real = math.copysign(1., x)
         imag = 4. * math.sin(y) * math.cos(y) * math.exp(-2.*fabs(x))
     else:
         tx = math.tanh(x)
@@ -489,11 +489,11 @@
         # and sin(phi) to figure out the signs.
         if isinf(r) and isfinite(phi) and phi != 0.:
             if r > 0:
-                real = copysign(INF, math.cos(phi))
-                imag = copysign(INF, math.sin(phi))
+                real = math.copysign(INF, math.cos(phi))
+                imag = math.copysign(INF, math.sin(phi))
             else:
-                real = -copysign(INF, math.cos(phi))
-                imag = -copysign(INF, math.sin(phi))
+                real = -math.copysign(INF, math.cos(phi))
+                imag = -math.copysign(INF, math.sin(phi))
             z = (real, imag)
         else:
             z = rect_special_values[special_type(r)][special_type(phi)]
@@ -516,21 +516,21 @@
         return NAN
     if isinf(y):
         if isinf(x):
-            if copysign(1., x) == 1.:
+            if math.copysign(1., x) == 1.:
                 # atan2(+-inf, +inf) == +-pi/4
-                return copysign(0.25 * math.pi, y)
+                return math.copysign(0.25 * math.pi, y)
             else:
                 # atan2(+-inf, -inf) == +-pi*3/4
-                return copysign(0.75 * math.pi, y)
+                return math.copysign(0.75 * math.pi, y)
         # atan2(+-inf, x) == +-pi/2 for finite x
-        return copysign(0.5 * math.pi, y)
+        return math.copysign(0.5 * math.pi, y)
     if isinf(x) or y == 0.:
-        if copysign(1., x) == 1.:
+        if math.copysign(1., x) == 1.:
             # atan2(+-y, +inf) = atan2(+-0, +x) = +-0.
-            return copysign(0., y)
+            return math.copysign(0., y)
         else:
             # atan2(+-y, -inf) = atan2(+-0., -x) = +-pi.
-            return copysign(math.pi, y)
+            return math.copysign(math.pi, y)
     return math.atan2(y, x)
 
 
diff --git a/rpython/rlib/rfloat.py b/rpython/rlib/rfloat.py
--- a/rpython/rlib/rfloat.py
+++ b/rpython/rlib/rfloat.py
@@ -1,7 +1,7 @@
 """Float constants"""
 
 import math, struct
-from math import isinf, isnan, copysign, acosh, asinh, atanh, log1p, expm1
+from math import isinf, isnan, acosh, asinh, atanh, log1p, expm1
 
 from rpython.annotator.model import SomeString, SomeChar
 from rpython.rlib import objectmodel, unroll
@@ -131,7 +131,7 @@
     # multiple of 0.5 * 10**n for n >= 23 takes at least 54 bits of
     # precision to represent exactly.
 
-    sign = copysign(1.0, value)
+    sign = math.copysign(1.0, value)
     value = abs(value)
 
     # find 2-valuation value
@@ -234,7 +234,7 @@
     absx = abs(x)
     r = math.floor(absx + 0.5)
     if r - absx < 1.0:
-        return copysign(r, x)
+        return math.copysign(r, x)
     else:
         # 'absx' is just in the wrong range: its exponent is precisely
         # the one for which all integers are representable but not any
@@ -258,7 +258,7 @@
         # absx == n + 0.5  for a non-negative integer 'n'
         # absx * 0.5 == n//2 + 0.25 or 0.75, which we round to nearest
         r = math.floor(absx * 0.5 + 0.5) * 2.0
-    return copysign(r, x)
+    return math.copysign(r, x)
 
 @not_rpython
 def isfinite(x):
@@ -362,7 +362,7 @@
         r = math.sin(math.pi * (y - 2.))
     else:
         raise AssertionError("should not reach")
-    return copysign(1., x) * r
+    return math.copysign(1., x) * r
 
 _lanczos_g = 6.024680040776729583740234375
 _lanczos_g_minus_half = 5.524680040776729583740234375
diff --git a/rpython/rlib/rstruct/ieee.py b/rpython/rlib/rstruct/ieee.py
--- a/rpython/rlib/rstruct/ieee.py
+++ b/rpython/rlib/rstruct/ieee.py
@@ -151,7 +151,7 @@
     else:
         raise ValueError("invalid size value")
 
-    sign = rfloat.copysign(1.0, x) < 0.0
+    sign = math.copysign(1.0, x) < 0.0
     if rfloat.isinf(x):
         mant = r_ulonglong(0)
         exp = MAX_EXP - MIN_EXP + 2
@@ -216,7 +216,7 @@
     else:
         raise ValueError("invalid size value")
 
-    sign = rfloat.copysign(1.0, x) < 0.0
+    sign = math.copysign(1.0, x) < 0.0
     if rfloat.isinf(x):
         mant = r_ulonglong(0)
         exp = MAX_EXP - MIN_EXP + 2
diff --git a/rpython/rlib/special_value.py b/rpython/rlib/special_value.py
--- a/rpython/rlib/special_value.py
+++ b/rpython/rlib/special_value.py
@@ -1,5 +1,5 @@
 import math
-from rpython.rlib.rfloat import isnan, isinf, copysign
+from rpython.rlib.rfloat import isnan, isinf
 
 # code to deal with special values (infinities, NaNs, ...)
 #
@@ -27,7 +27,7 @@
             else:
                 return ST_NEG
         else:
-            if copysign(1., d) == 1.:
+            if math.copysign(1., d) == 1.:
                 return ST_PZERO
             else:
                 return ST_NZERO
@@ -166,4 +166,4 @@
     (N,N),   (N,N), (N,Z),    (N,Z),     (N,N), (N,N),   (N,N),
     ])
 
-assert copysign(1., acosh_special_values[5][2][1]) == -1.
+assert math.copysign(1., acosh_special_values[5][2][1]) == -1.
diff --git a/rpython/rlib/test/test_rfloat.py b/rpython/rlib/test/test_rfloat.py
--- a/rpython/rlib/test/test_rfloat.py
+++ b/rpython/rlib/test/test_rfloat.py
@@ -1,7 +1,6 @@
 import sys, py
 
 from rpython.rlib.rfloat import float_as_rbigint_ratio
-from rpython.rlib.rfloat import copysign
 from rpython.rlib.rfloat import round_away
 from rpython.rlib.rfloat import round_double
 from rpython.rlib.rfloat import erf, erfc, gamma, lgamma, isnan
@@ -9,13 +8,6 @@
 from rpython.rlib.rfloat import string_to_float
 from rpython.rlib.rbigint import rbigint
 
-def test_copysign():
-    assert copysign(1, 1) == 1
-    assert copysign(-1, 1) == 1
-    assert copysign(-1, -1) == -1
-    assert copysign(1, -1) == -1
-    assert copysign(1, -0.) == -1
-
 def test_round_away():
     assert round_away(.1) == 0.
     assert round_away(.5) == 1.
diff --git a/rpython/rtyper/extfuncregistry.py 
b/rpython/rtyper/extfuncregistry.py
--- a/rpython/rtyper/extfuncregistry.py
+++ b/rpython/rtyper/extfuncregistry.py
@@ -30,9 +30,9 @@
         ('isinf', [float], bool),
         ('isnan', [float], bool),
         ('isfinite', [float], bool),
-        ('copysign', [float, float], float),
     ]),
     (math, [
+       ('copysign', [float, float], float),
        ('floor', [float], float),
        ('sqrt', [float], float),
        ('log', [float], float),
diff --git a/rpython/rtyper/lltypesystem/module/test/test_llinterp_math.py 
b/rpython/rtyper/lltypesystem/module/test/test_llinterp_math.py
--- a/rpython/rtyper/lltypesystem/module/test/test_llinterp_math.py
+++ b/rpython/rtyper/lltypesystem/module/test/test_llinterp_math.py
@@ -84,8 +84,8 @@
 
     def test_log1p_zero(self):
         def f(x):
-            x = rfloat.copysign(0.0, x)
-            return rfloat.copysign(1.0, rfloat.log1p(x))
+            x = math.copysign(0.0, x)
+            return math.copysign(1.0, rfloat.log1p(x))
 
         assert self.interpret(f, [3.0]) == 1.0
         assert self.interpret(f, [-2.0]) == -1.0
diff --git a/rpython/rtyper/test/test_rfloat.py 
b/rpython/rtyper/test/test_rfloat.py
--- a/rpython/rtyper/test/test_rfloat.py
+++ b/rpython/rtyper/test/test_rfloat.py
@@ -1,3 +1,4 @@
+import math
 import sys
 from rpython.translator.translator import TranslationContext
 from rpython.rtyper.test import snippet
@@ -147,9 +148,8 @@
         self.interpret(fn, [1.0, 2.0, 3.0])
 
     def test_copysign(self):
-        from rpython.rlib import rfloat
         def fn(x, y):
-            return rfloat.copysign(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
diff --git a/rpython/tool/uid.py b/rpython/tool/uid.py
--- a/rpython/tool/uid.py
+++ b/rpython/tool/uid.py
@@ -1,3 +1,4 @@
+import math
 import struct
 
 HUGEVAL_BYTES = struct.calcsize('P')
@@ -28,8 +29,7 @@
         # we also have to avoid confusing 0.0 and -0.0 (needed e.g. for
         # translating the cmath module)
         if key[0] is float and not self.value:
-            from rpython.rlib.rfloat import copysign
-            if copysign(1., self.value) == -1.:    # -0.0
+            if math.copysign(1., self.value) == -1.:    # -0.0
                 key = (float, "-0.0")
         #
         try:
diff --git a/rpython/translator/c/primitive.py 
b/rpython/translator/c/primitive.py
--- a/rpython/translator/c/primitive.py
+++ b/rpython/translator/c/primitive.py
@@ -1,3 +1,4 @@
+import math
 import sys
 
 from rpython.rlib.objectmodel import Symbolic, ComputedIntSymbolic, 
CDefinedIntSymbolic
@@ -113,10 +114,7 @@
         return '%dLL' % value
 
 def is_positive_nan(value):
-    # bah.  we don't have math.copysign() if we're running Python 2.5
-    import struct
-    c = struct.pack("!d", value)[0]
-    return {'\x7f': True, '\xff': False}[c]
+    return math.copysign(1, value) > 0
 
 def name_float(value, db):
     if isinf(value):
diff --git a/rpython/translator/c/test/test_genc.py 
b/rpython/translator/c/test/test_genc.py
--- a/rpython/translator/c/test/test_genc.py
+++ b/rpython/translator/c/test/test_genc.py
@@ -1,4 +1,5 @@
 import ctypes
+import math
 import re
 from collections import OrderedDict
 
@@ -402,7 +403,7 @@
     assert isnan(res)
 
 def test_nan_and_special_values():
-    from rpython.rlib.rfloat import isnan, isinf, isfinite, copysign
+    from rpython.rlib.rfloat import isnan, isinf, isfinite
     inf = 1e300 * 1e300
     assert isinf(inf)
     nan = inf/inf
@@ -413,8 +414,8 @@
             (-inf,  lambda x: isinf(x) and x < 0.0),
             (nan,   isnan),
             (42.0,  isfinite),
-            (0.0,   lambda x: not x and copysign(1., x) == 1.),
-            (-0.0,  lambda x: not x and copysign(1., x) == -1.),
+            (0.0,   lambda x: not x and math.copysign(1., x) == 1.),
+            (-0.0,  lambda x: not x and math.copysign(1., x) == -1.),
             ]:
         def f():
             return value
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to