我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用math.asinh()。
def get(self): self.x += self.config.get('dx', 0.1) val = eval(self.config.get('function', 'sin(x)'), { 'sin': math.sin, 'sinh': math.sinh, 'cos': math.cos, 'cosh': math.cosh, 'tan': math.tan, 'tanh': math.tanh, 'asin': math.asin, 'acos': math.acos, 'atan': math.atan, 'asinh': math.asinh, 'acosh': math.acosh, 'atanh': math.atanh, 'log': math.log, 'abs': abs, 'e': math.e, 'pi': math.pi, 'x': self.x }) return self.createEvent('ok', 'Sine wave', val)
def _intSecAtan(x): # In : sympy.integrate(sp.sec(sp.atan(x))) # Out: x*sqrt(x**2 + 1)/2 + asinh(x)/2 return x * math.sqrt(x**2 + 1)/2 + math.asinh(x)/2
def acsch(x): if type(x) in dtypes: return math.asinh(1. / x) return functor1(acsch, x)
def testAsinh(self): self.assertRaises(TypeError, math.asinh) self.ftest('asinh(0)', math.asinh(0), 0) self.ftest('asinh(1)', math.asinh(1), 0.88137358701954305) self.ftest('asinh(-1)', math.asinh(-1), -0.88137358701954305) self.assertEqual(math.asinh(INF), INF) self.assertEqual(math.asinh(NINF), NINF) self.assertTrue(math.isnan(math.asinh(NAN)))
def asinh(node): return merge([node], math.asinh)
def acos(x): _acos_special = [ [3*pi/4+infj, pi+infj, pi+infj, pi-infj, pi-infj, 3*pi/4-infj, nan+infj], [pi/2+infj, None, None, None, None, pi/2-infj, nan+nanj], [pi/2+infj, None, None, None, None, pi/2-infj, pi/2+nanj], [pi/2+infj, None, None, None, None, pi/2-infj, pi/2+nanj], [pi/2+infj, None, None, None, None, pi/2-infj, nan+nanj], [pi/4+infj, infj, infj, 0.0-infj, 0.0-infj, pi/4-infj, nan+infj], [nan+infj, nan+nanj, nan+nanj, nan+nanj, nan+nanj, nan-infj, nan+nanj] ] z = _make_complex(x) if not isfinite(z): return _acos_special[_special_type(z.real)][_special_type(z.imag)] if abs(z.real) > _LARGE_DOUBLE or abs(z.imag) > _LARGE_DOUBLE: if z.real < 0: imag = -math.copysign(math.log(math.hypot(z.real/2, z.imag/2)) + 2 * _LOG_2, z.imag) else: imag = math.copysign(math.log(math.hypot(z.real/2, z.imag/2)) + 2 * _LOG_2, -z.imag) return complex(math.atan2(abs(z.imag), z.real), imag) s1 = sqrt(complex(1.0 - z.real, -z.imag)) s2 = sqrt(complex(1.0 + z.real, z.imag)) return complex(2 * math.atan2(s1.real, s2.real), math.asinh(s2.real*s1.imag - s2.imag*s1.real))
def asin(x): z = _make_complex(x) z = asinh(complex(-z.imag, z.real)) return complex(z.imag, -z.real)
def acosh(x): z = _make_complex(x) if abs(z.real) > _LARGE_DOUBLE or abs(z.imag) > _LARGE_DOUBLE: return complex(math.log(math.hypot(z.real/2, z.imag/2)) + 2*_LOG_2, math.atan2(z.imag, z.real)) s1 = sqrt(complex(z.real-1, z.imag)) s2 = sqrt(complex(z.real+1, z.imag)) return complex(math.asinh(s1.real*s2.real + s1.imag*s2.imag), 2*math.atan2(s1.imag, s2.real))
def asinh(x): _asinh_special = [ [-inf-1j*pi/4, complex(-float("inf"), -0.0), complex(-float("inf"), -0.0), complex(-float("inf"), 0.0), complex(-float("inf"), 0.0), -inf+1j*pi/4, -inf+nanj], [-inf-1j*pi/2, None, None, None, None, -inf+1j*pi/2, nan+nanj], [-inf-1j*pi/2, None, None, None, None, -inf+1j*pi/2, nan+nanj], [inf-1j*pi/2, None, None, None, None, inf+1j*pi/2, nan+nanj], [inf-1j*pi/2, None, None, None, None, inf+1j*pi/2, nan+nanj], [inf-1j*pi/4, complex(float("inf"), -0.0), complex(float("inf"), -0.0), inf, inf, inf+1j*pi/4, inf+nanj], [inf+nanj, nan+nanj, complex(float("nan"), -0.0), nan, nan+nanj, inf+nanj, nan+nanj] ] z = _make_complex(x) if not isfinite(z): return _asinh_special[_special_type(z.real)][_special_type(z.imag)] if abs(z.real) > _LARGE_DOUBLE or abs(z.imag) > _LARGE_DOUBLE: if z.imag >= 0: real = math.copysign(math.log(math.hypot(z.imag/2, z.real/2)) + 2 * _LOG_2, z.real) else: real = -math.copysign(math.log(math.hypot(z.imag/2, z.real/2)) + 2 * _LOG_2, -z.real) return complex(real, math.atan2(z.imag, abs(z.real))) s1 = sqrt(complex(1+z.imag, -z.real)) s2 = sqrt(complex(1-z.imag, z.real)) return complex(math.asinh(s1.real*s2.imag-s2.real*s1.imag), math.atan2(z.imag, s1.real*s2.real - s1.imag*s2.imag))
def test_asinh(self): self.assertEqual(session.source("Test", x=real(3.14, 6.5)).type("asinh(x)"), real(math.asinh(3.14), math.asinh(6.5))) self.assertEqual(session.source("Test", x=real(3.14, almost(6.5))).type("asinh(x)"), real(math.asinh(3.14), almost(math.asinh(6.5)))) self.assertEqual(session.source("Test", x=real(3.14, inf)).type("asinh(x)"), real(math.asinh(3.14), inf)) self.assertEqual(session.source("Test", x=real(3.14, almost(inf))).type("asinh(x)"), real(math.asinh(3.14), almost(inf))) self.assertEqual(session.source("Test", x=real).type("asinh(x)"), real) self.assertEqual(session.source("Test", x=extended).type("asinh(x)"), extended) for entry in numerical.toPython(y = "y", a = "asinh(y)").submit(): self.assertEqual(entry.a, math.asinh(entry.y))
def asinh(arg): return generate_intrinsic_function_expression(arg, 'asinh', math.asinh)
def __init__(self): ParameterCell.__init__(self) self.a = None self.b = None self.c = None self.d = None self.formula = "" self._previous_values = [None, None, None, None] self._formula_globals = globals(); self._formula_locals = { "exp":math.exp, "pow":math.pow, "log":math.log, "log10":math.log10, "acos":math.acos, "asin":math.asin, "atan":math.atan, "atan2":math.atan2, "cos":math.cos, "hypot":math.hypot, "sin":math.sin, "tan":math.tan, "degrees":math.degrees, "radians":math.radians, "acosh":math.acosh, "asinh":math.asinh, "atanh":math.atanh, "cosh":math.cosh, "sinh":math.sinh, "tanh":math.tanh, "pi":math.pi, "e":math.e, "ceil":math.ceil, "sign":ParameterMathFun.signum, "abs":math.fabs, "floor":math.floor, "mod":math.fmod, "sqrt":math.sqrt, "curt":ParameterMathFun.curt, "str":str, "int":int, "float":float }
def test_one(): from math import sin, cos, tan, asin, acos, atan from math import sinh, cosh, tanh, asinh, acosh, atanh from math import exp, expm1, log, log10, log1p, sqrt, lgamma from math import fabs, ceil, floor, trunc, erf, erfc try: from math import log2 except ImportError: def log2(x): return log(x) / log(2) def wrapper(f, v): try: return f(v) except ValueError: if f == sqrt: return float('nan') if v >= 0: return float('inf') else: return -float('inf') def compare(a, b): if isfinite(a) and isfinite(b): return assert_almost_equals(a, b) return str(a) == str(b) for f in [sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, exp, expm1, log, log2, log10, log1p, sqrt, lgamma, fabs, ceil, floor, trunc, erf, erfc]: for p in [0.5, 1]: a = random_lst(p=p) b = SparseArray.fromlist(a) c = getattr(b, f.__name__)() res = [wrapper(f, x) for x in a] index = [k for k, v in enumerate(res) if v != 0] res = [x for x in res if x != 0] print(f, p, c.non_zero, len(res)) assert c.non_zero == len(res) [assert_almost_equals(v, w) for v, w in zip(index, c.index)] [compare(v, w) for v, w in zip(res, c.data)]