Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r88554:ccde5f15328f
Date: 2016-11-22 20:42 +0000
http://bitbucket.org/pypy/pypy/changeset/ccde5f15328f/
Log: Remove obsolete reimplementations of stdlib functions
diff --git a/rpython/rlib/rfloat.py b/rpython/rlib/rfloat.py
--- a/rpython/rlib/rfloat.py
+++ b/rpython/rlib/rfloat.py
@@ -1,6 +1,7 @@
"""Float constants"""
import math, struct
+from math import isinf, isnan, copysign, acosh, asinh, atanh, log1p, expm1
from rpython.annotator.model import SomeString, SomeChar
from rpython.rlib import objectmodel, unroll
@@ -184,104 +185,6 @@
INFINITY = 1e200 * 1e200
NAN = abs(INFINITY / INFINITY) # bah, INF/INF gives us -NAN?
-try:
- # Try to get math functions added in 2.6.
- from math import isinf, isnan, copysign, acosh, asinh, atanh, log1p
-except ImportError:
- @not_rpython
- def isinf(x):
- return x == INFINITY or x == -INFINITY
-
- @not_rpython
- def isnan(v):
- return v != v
-
- @not_rpython
- def copysign(x, y):
- """Return x with the sign of y"""
- if x < 0.:
- x = -x
- if y > 0. or (y == 0. and math.atan2(y, -1.) > 0.):
- return x
- else:
- return -x
-
- _2_to_m28 = 3.7252902984619141E-09; # 2**-28
- _2_to_p28 = 268435456.0; # 2**28
- _ln2 = 6.93147180559945286227E-01
-
- @not_rpython
- def acosh(x):
- if isnan(x):
- return NAN
- if x < 1.:
- raise ValueError("math domain error")
- if x >= _2_to_p28:
- if isinf(x):
- return x
- else:
- return math.log(x) + _ln2
- if x == 1.:
- return 0.
- if x >= 2.:
- t = x * x
- return math.log(2. * x - 1. / (x + math.sqrt(t - 1.0)))
- t = x - 1.0
- return log1p(t + math.sqrt(2. * t + t * t))
-
- @not_rpython
- def asinh(x):
- absx = abs(x)
- if not isfinite(x):
- return x
- if absx < _2_to_m28:
- return x
- if absx > _2_to_p28:
- w = math.log(absx) + _ln2
- elif absx > 2.:
- w = math.log(2. * absx + 1. / (math.sqrt(x * x + 1.) + absx))
- else:
- t = x * x
- w = log1p(absx + t / (1. + math.sqrt(1. + t)))
- return copysign(w, x)
-
- @not_rpython
- def atanh(x):
- if isnan(x):
- return x
- absx = abs(x)
- if absx >= 1.:
- raise ValueError("math domain error")
- if absx < _2_to_m28:
- return x
- if absx < .5:
- t = absx + absx
- t = .5 * log1p(t + t * absx / (1. - absx))
- else:
- t = .5 * log1p((absx + absx) / (1. - absx))
- return copysign(t, x)
-
- @not_rpython
- def log1p(x):
- if abs(x) < DBL_EPSILON // 2.:
- return x
- elif -.5 <= x <= 1.:
- y = 1. + x
- return math.log(y) - ((y - 1.) - x) / y
- else:
- return math.log(1. + x)
-
-try:
- from math import expm1 # Added in Python 2.7.
-except ImportError:
- @not_rpython
- def expm1(x):
- if abs(x) < .7:
- u = math.exp(x)
- if u == 1.:
- return x
- return (u - 1.) * x / math.log(u)
- return math.exp(x) - 1.
def log2(x):
# Uses an algorithm that should:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit