From 9de85113674dca36f60e9dcc29f5302bf283c065 Mon Sep 17 00:00:00 2001 From: Tony Jinwoo Ahn Date: Sat, 18 Sep 2021 19:42:09 +0900 Subject: [PATCH] Add tan() and tanh() for cmath Signed-off-by: Tony Jinwoo Ahn --- Lib/test/test_cmath.py | 6 ++---- vm/src/stdlib/cmath.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py index 8dc0acab0e..0f4d1c7433 100644 --- a/Lib/test/test_cmath.py +++ b/Lib/test/test_cmath.py @@ -56,9 +56,9 @@ class CMathTests(unittest.TestCase): # # list of all functions in cmath test_functions = [getattr(cmath, fname) for fname in [ - 'sin','cos','log','log10','sqrt','acosh' + 'sin','cos','log','log10','sqrt','acosh','tan','tanh' # 'exp','acos','asin','asinh', - # 'atan','atanh','sinh','cosh','tan','tanh' + # 'atan','atanh','sinh','cosh' ]] # test first and second arguments independently for 2-argument log # test_functions.append(lambda x : cmath.log(x, 1729. + 0j)) @@ -590,8 +590,6 @@ class CMathTests(unittest.TestCase): self.assertTrue(cmath.isinf(complex(NAN, INF))) self.assertTrue(cmath.isinf(complex(INF, NAN))) - # TODO: RUSTPYTHON - @unittest.expectedFailure @requires_IEEE_754 def testTanhSign(self): for z in complex_zeros: diff --git a/vm/src/stdlib/cmath.rs b/vm/src/stdlib/cmath.rs index 4c8d605c5d..0d3dd9ceea 100644 --- a/vm/src/stdlib/cmath.rs +++ b/vm/src/stdlib/cmath.rs @@ -113,6 +113,18 @@ mod cmath { z.to_complex().acosh() } + /// Return the tangent of z. + #[pyfunction] + fn tan(z: IntoPyComplex) -> Complex64 { + z.to_complex().tan() + } + + /// Return the hyperbolic tangent of z. + #[pyfunction] + fn tanh(z: IntoPyComplex) -> Complex64 { + z.to_complex().tanh() + } + #[derive(FromArgs)] struct IsCloseArgs { #[pyarg(positional)]