[pypy-svn] pypy cmath: (lac, arigo)
arigo
commits-noreply at bitbucket.org
Mon Jan 17 18:34:12 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: cmath
Changeset: r40802:136e8283a2fa
Date: 2011-01-17 18:25 +0100
http://bitbucket.org/pypy/pypy/changeset/136e8283a2fa/
Log: (lac, arigo)
sinh().
diff --git a/pypy/module/cmath/__init__.py b/pypy/module/cmath/__init__.py
--- a/pypy/module/cmath/__init__.py
+++ b/pypy/module/cmath/__init__.py
@@ -16,6 +16,7 @@
'log10': "Return the base-10 logarithm of x.",
'exp': "Return the exponential value e**x.",
'cosh': "Return the hyperbolic cosine of x.",
+ 'sinh': "Return the hyperbolic sine of x.",
}
diff --git a/pypy/module/cmath/interp_cmath.py b/pypy/module/cmath/interp_cmath.py
--- a/pypy/module/cmath/interp_cmath.py
+++ b/pypy/module/cmath/interp_cmath.py
@@ -17,6 +17,7 @@
from pypy.module.cmath.special_value import log_special_values
from pypy.module.cmath.special_value import exp_special_values
from pypy.module.cmath.special_value import cosh_special_values
+from pypy.module.cmath.special_value import sinh_special_values
def unaryfn(c_func):
@@ -350,4 +351,39 @@
else:
real = math.cos(y) * math.cosh(x)
imag = math.sin(y) * math.sinh(x)
+ if isinf(real) or isinf(imag):
+ raise OverflowError("math range error")
return real, imag
+
+
+ at unaryfn
+def c_sinh(x, y):
+ # special treatment for sinh(+/-inf + iy) if y is finite and nonzero
+ 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))
+ else:
+ real = -copysign(INF, math.cos(y))
+ imag = copysign(INF, math.sin(y))
+ r = (real, imag)
+ else:
+ r = sinh_special_values[special_type(x)][special_type(y)]
+
+ # need to raise ValueError if y is +/- infinity and x is not
+ # a NaN
+ if isinf(y) and not isnan(x):
+ raise ValueError("math domain error")
+ return r
+
+ if fabs(x) > CM_LOG_LARGE_DOUBLE:
+ x_minus_one = x - 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:
+ real = math.cos(y) * math.sinh(x)
+ imag = math.sin(y) * math.cosh(x)
+ if isinf(real) or isinf(imag):
+ raise OverflowError("math range error")
+ return real, imag
diff --git a/pypy/module/cmath/special_value.py b/pypy/module/cmath/special_value.py
--- a/pypy/module/cmath/special_value.py
+++ b/pypy/module/cmath/special_value.py
@@ -135,3 +135,13 @@
(INF,N), (U,U), (INF,-0.), (INF,0.), (U,U), (INF,N), (INF,N),
(N,N), (N,N), (N,0.), (N,0.), (N,N), (N,N), (N,N),
])
+
+sinh_special_values = build_table([
+ (INF,N), (U,U), (-INF,-0.), (-INF,0.), (U,U), (INF,N), (INF,N),
+ (N,N), (U,U), (U,U), (U,U), (U,U), (N,N), (N,N),
+ (0.,N), (U,U), (-0.,-0.), (-0.,0.), (U,U), (0.,N), (0.,N),
+ (0.,N), (U,U), (0.,-0.), (0.,0.), (U,U), (0.,N), (0.,N),
+ (N,N), (U,U), (U,U), (U,U), (U,U), (N,N), (N,N),
+ (INF,N), (U,U), (INF,-0.), (INF,0.), (U,U), (INF,N), (INF,N),
+ (N,N), (N,N), (N,-0.), (N,0.), (N,N), (N,N), (N,N),
+ ])
More information about the Pypy-commit
mailing list