Python cmath.tanh() Examples
The following are 15
code examples of cmath.tanh().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cmath
, or try the search function
.
Example #1
Source File: test_cmath.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def testTanhSign(self): for z in complex_zeros: self.assertComplexIdentical(cmath.tanh(z), z) # The algorithm used for atan and atanh makes use of the system # log1p function; If that system function doesn't respect the sign # of zero, then atan and atanh will also have difficulties with # the sign of complex zeros.
Example #2
Source File: test_cmath.py From ironpython3 with Apache License 2.0 | 5 votes |
def testTanhSign(self): for z in complex_zeros: self.assertComplexIdentical(cmath.tanh(z), z) # The algorithm used for atan and atanh makes use of the system # log1p function; If that system function doesn't respect the sign # of zero, then atan and atanh will also have difficulties with # the sign of complex zeros.
Example #3
Source File: math_functions.py From jhTAlib with GNU General Public License v3.0 | 5 votes |
def TANH(df, price='Close'): """ Hyperbolic Tangent Returns: list of floats = jhta.TANH(df, price='Close') """ return [cmath.tanh(df[price][i]).real for i in range(len(df[price]))]
Example #4
Source File: test_cmath.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def testTanhSign(self): for z in complex_zeros: self.assertComplexIdentical(cmath.tanh(z), z) # The algorithm used for atan and atanh makes use of the system # log1p function; If that system function doesn't respect the sign # of zero, then atan and atanh will also have difficulties with # the sign of complex zeros.
Example #5
Source File: test_cmath_jy.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_tanh(self): self.assertAlmostEqual(complex(1.00071, 0.00490826), cmath.tanh(complex(3, 4)))
Example #6
Source File: test_cmath_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_tanh(self): self.assertAlmostEqual(complex(1.00071, 0.00490826), cmath.tanh(complex(3, 4)))
Example #7
Source File: test_functions.py From altanalyze with Apache License 2.0 | 5 votes |
def test_trig_hyperb_basic(): for x in (list(range(100)) + list(range(-100,0))): t = x / 4.1 assert cos(mpf(t)).ae(math.cos(t)) assert sin(mpf(t)).ae(math.sin(t)) assert tan(mpf(t)).ae(math.tan(t)) assert cosh(mpf(t)).ae(math.cosh(t)) assert sinh(mpf(t)).ae(math.sinh(t)) assert tanh(mpf(t)).ae(math.tanh(t)) assert sin(1+1j).ae(cmath.sin(1+1j)) assert sin(-4-3.6j).ae(cmath.sin(-4-3.6j)) assert cos(1+1j).ae(cmath.cos(1+1j)) assert cos(-4-3.6j).ae(cmath.cos(-4-3.6j))
Example #8
Source File: test_functions.py From altanalyze with Apache License 2.0 | 5 votes |
def test_invhyperb_inaccuracy(): mp.dps = 15 assert (asinh(1e-5)*10**5).ae(0.99999999998333333) assert (asinh(1e-10)*10**10).ae(1) assert (asinh(1e-50)*10**50).ae(1) assert (asinh(-1e-5)*10**5).ae(-0.99999999998333333) assert (asinh(-1e-10)*10**10).ae(-1) assert (asinh(-1e-50)*10**50).ae(-1) assert asinh(10**20).ae(46.744849040440862) assert asinh(-10**20).ae(-46.744849040440862) assert (tanh(1e-10)*10**10).ae(1) assert (tanh(-1e-10)*10**10).ae(-1) assert (atanh(1e-10)*10**10).ae(1) assert (atanh(-1e-10)*10**10).ae(-1)
Example #9
Source File: test_functions.py From altanalyze with Apache License 2.0 | 5 votes |
def test_complex_functions(): for x in (list(range(10)) + list(range(-10,0))): for y in (list(range(10)) + list(range(-10,0))): z = complex(x, y)/4.3 + 0.01j assert exp(mpc(z)).ae(cmath.exp(z)) assert log(mpc(z)).ae(cmath.log(z)) assert cos(mpc(z)).ae(cmath.cos(z)) assert sin(mpc(z)).ae(cmath.sin(z)) assert tan(mpc(z)).ae(cmath.tan(z)) assert sinh(mpc(z)).ae(cmath.sinh(z)) assert cosh(mpc(z)).ae(cmath.cosh(z)) assert tanh(mpc(z)).ae(cmath.tanh(z))
Example #10
Source File: test_functions.py From altanalyze with Apache License 2.0 | 5 votes |
def test_tanh(): mp.dps = 15 assert tanh(0) == 0 assert tanh(inf) == 1 assert tanh(-inf) == -1 assert isnan(tanh(nan)) assert tanh(mpc('inf', '0')) == 1
Example #11
Source File: test_cmath_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_tanh(self): self.assertAlmostEqual(complex(1.00071, 0.00490826), cmath.tanh(complex(3, 4)))
Example #12
Source File: test_cmath.py From Fluid-Designer with GNU General Public License v3.0 | 4 votes |
def test_cmath_matches_math(self): # check that corresponding cmath and math functions are equal # for floats in the appropriate range # test_values in (0, 1) test_values = [0.01, 0.1, 0.2, 0.5, 0.9, 0.99] # test_values for functions defined on [-1., 1.] unit_interval = test_values + [-x for x in test_values] + \ [0., 1., -1.] # test_values for log, log10, sqrt positive = test_values + [1.] + [1./x for x in test_values] nonnegative = [0.] + positive # test_values for functions defined on the whole real line real_line = [0.] + positive + [-x for x in positive] test_functions = { 'acos' : unit_interval, 'asin' : unit_interval, 'atan' : real_line, 'cos' : real_line, 'cosh' : real_line, 'exp' : real_line, 'log' : positive, 'log10' : positive, 'sin' : real_line, 'sinh' : real_line, 'sqrt' : nonnegative, 'tan' : real_line, 'tanh' : real_line} for fn, values in test_functions.items(): float_fn = getattr(math, fn) complex_fn = getattr(cmath, fn) for v in values: z = complex_fn(v) self.rAssertAlmostEqual(float_fn(v), z.real) self.assertEqual(0., z.imag) # test two-argument version of log with various bases for base in [0.5, 2., 10.]: for v in positive: z = cmath.log(v, base) self.rAssertAlmostEqual(math.log(v, base), z.real) self.assertEqual(0., z.imag)
Example #13
Source File: test_cmath.py From ironpython3 with Apache License 2.0 | 4 votes |
def test_cmath_matches_math(self): # check that corresponding cmath and math functions are equal # for floats in the appropriate range # test_values in (0, 1) test_values = [0.01, 0.1, 0.2, 0.5, 0.9, 0.99] # test_values for functions defined on [-1., 1.] unit_interval = test_values + [-x for x in test_values] + \ [0., 1., -1.] # test_values for log, log10, sqrt positive = test_values + [1.] + [1./x for x in test_values] nonnegative = [0.] + positive # test_values for functions defined on the whole real line real_line = [0.] + positive + [-x for x in positive] test_functions = { 'acos' : unit_interval, 'asin' : unit_interval, 'atan' : real_line, 'cos' : real_line, 'cosh' : real_line, 'exp' : real_line, 'log' : positive, 'log10' : positive, 'sin' : real_line, 'sinh' : real_line, 'sqrt' : nonnegative, 'tan' : real_line, 'tanh' : real_line} for fn, values in test_functions.items(): float_fn = getattr(math, fn) complex_fn = getattr(cmath, fn) for v in values: z = complex_fn(v) self.rAssertAlmostEqual(float_fn(v), z.real) self.assertEqual(0., z.imag) # test two-argument version of log with various bases for base in [0.5, 2., 10.]: for v in positive: z = cmath.log(v, base) self.rAssertAlmostEqual(math.log(v, base), z.real) self.assertEqual(0., z.imag)
Example #14
Source File: test_cmath.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 4 votes |
def test_cmath_matches_math(self): # check that corresponding cmath and math functions are equal # for floats in the appropriate range # test_values in (0, 1) test_values = [0.01, 0.1, 0.2, 0.5, 0.9, 0.99] # test_values for functions defined on [-1., 1.] unit_interval = test_values + [-x for x in test_values] + \ [0., 1., -1.] # test_values for log, log10, sqrt positive = test_values + [1.] + [1./x for x in test_values] nonnegative = [0.] + positive # test_values for functions defined on the whole real line real_line = [0.] + positive + [-x for x in positive] test_functions = { 'acos' : unit_interval, 'asin' : unit_interval, 'atan' : real_line, 'cos' : real_line, 'cosh' : real_line, 'exp' : real_line, 'log' : positive, 'log10' : positive, 'sin' : real_line, 'sinh' : real_line, 'sqrt' : nonnegative, 'tan' : real_line, 'tanh' : real_line} for fn, values in test_functions.items(): float_fn = getattr(math, fn) complex_fn = getattr(cmath, fn) for v in values: z = complex_fn(v) self.rAssertAlmostEqual(float_fn(v), z.real) self.assertEqual(0., z.imag) # test two-argument version of log with various bases for base in [0.5, 2., 10.]: for v in positive: z = cmath.log(v, base) self.rAssertAlmostEqual(math.log(v, base), z.real) self.assertEqual(0., z.imag)
Example #15
Source File: test_functions.py From altanalyze with Apache License 2.0 | 4 votes |
def test_perturbation_rounding(): mp.dps = 100 a = pi/10**50 b = -pi/10**50 c = 1 + a d = 1 + b mp.dps = 15 assert exp(a) == 1 assert exp(a, rounding='c') > 1 assert exp(b, rounding='c') == 1 assert exp(a, rounding='f') == 1 assert exp(b, rounding='f') < 1 assert cos(a) == 1 assert cos(a, rounding='c') == 1 assert cos(b, rounding='c') == 1 assert cos(a, rounding='f') < 1 assert cos(b, rounding='f') < 1 for f in [sin, atan, asinh, tanh]: assert f(a) == +a assert f(a, rounding='c') > a assert f(a, rounding='f') < a assert f(b) == +b assert f(b, rounding='c') > b assert f(b, rounding='f') < b for f in [asin, tan, sinh, atanh]: assert f(a) == +a assert f(b) == +b assert f(a, rounding='c') > a assert f(b, rounding='c') > b assert f(a, rounding='f') < a assert f(b, rounding='f') < b assert ln(c) == +a assert ln(d) == +b assert ln(c, rounding='c') > a assert ln(c, rounding='f') < a assert ln(d, rounding='c') > b assert ln(d, rounding='f') < b assert cosh(a) == 1 assert cosh(b) == 1 assert cosh(a, rounding='c') > 1 assert cosh(b, rounding='c') > 1 assert cosh(a, rounding='f') == 1 assert cosh(b, rounding='f') == 1