Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions Lib/test/test_cmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ class CMathTests(unittest.TestCase):
# commented out to allow incremented addition of functions.
#
# list of all functions in cmath
# test_functions = [getattr(cmath, fname) for fname in [
# 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh',
# 'cos', 'cosh', 'exp', 'log', 'log10', 'sin', 'sinh',
# 'sqrt', 'tan', 'tanh']]
test_functions = [getattr(cmath, fname) for fname in ['sqrt']]
Comment thread
DimitrisJim marked this conversation as resolved.
Resolved
# test first and second arguments independently for 2-argument log
# test_functions.append(lambda x : cmath.log(x, 1729. + 0j))
# test_functions.append(lambda x : cmath.log(14.-27j, x))
Expand Down Expand Up @@ -179,8 +176,6 @@ def test_infinity_and_nan_constants(self):
self.assertEqual(repr(cmath.nan), "nan")
self.assertEqual(repr(cmath.nanj), "nanj")

# TODO: RUSTPYTHON
@unittest.expectedFailure
Comment thread
DimitrisJim marked this conversation as resolved.
Resolved
def test_user_object(self):
# Test automatic calling of __complex__ and __float__ by cmath
# functions
Expand Down Expand Up @@ -279,8 +274,6 @@ def __float__(self):
self.assertRaises(SomeException, f, MyComplexException())
self.assertRaises(SomeException, f, MyComplexExceptionOS())

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_input_type(self):
# ints should be acceptable inputs to all cmath
# functions, by virtue of providing a __float__ method
Expand Down Expand Up @@ -326,11 +319,16 @@ def test_cmath_matches_math(self):
'sinh' : real_line,
'sqrt' : nonnegative,
'tan' : real_line,
'tanh' : real_line}
'tanh' : real_line
}

for fn, values in test_functions.items():
float_fn = getattr(math, fn)
complex_fn = getattr(cmath, fn)
# TODO: RUSTPYTHON replace with 'complex_fn = getattr(cmath, fn)'
# when all functions have been added.
complex_fn = getattr(cmath, fn, None)
if complex_fn is None:
continue
for v in values:
z = complex_fn(v)
self.rAssertAlmostEqual(float_fn(v), z.real)
Expand Down
6 changes: 5 additions & 1 deletion vm/src/stdlib/cmath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ mod cmath {
let z = z.to_complex();
result_or_overflow(z, z.exp(), vm)
}

/// Return the square root of z.
#[pyfunction]
fn sqrt(z: IntoPyComplex) -> Complex64 {
z.to_complex().sqrt()
}
#[derive(FromArgs)]
struct IsCloseArgs {
#[pyarg(positional)]
Expand Down