Remove support for nth root of negative numbers with odd powers.

Although nth roots of negative numbers are real for odd n, the
statistics module doesn't make use of this. Remove support for
negative roots from the private _nth_root function, which
simplifies the test suite.
This commit is contained in:
Steven D'Aprano 2016-08-24 12:48:12 +10:00
parent e5803d9d2f
commit d6ea3011c5
2 changed files with 8 additions and 28 deletions

View file

@ -335,10 +335,7 @@ class _nroot_NS:
"""Handle nth root of Reals, treated as a float."""
assert isinstance(n, int) and n > 1
if x < 0:
if n%2 == 0:
raise ValueError('domain error: even root of negative number')
else:
return -_nroot_NS.nroot(-x, n)
raise ValueError('domain error: root of negative number')
elif x == 0:
return math.copysign(0.0, x)
elif x > 0:
@ -433,6 +430,8 @@ class _nroot_NS:
else:
# Preserve the input NAN.
return x
if x < 0:
raise ValueError('domain error: root of negative number')
if x.is_infinite():
return x
# FIXME this hasn't had the extensive testing of the float