diff options
| author | Steven D'Aprano <steve@pearwood.info> | 2016-08-24 12:48:12 +1000 |
|---|---|---|
| committer | Steven D'Aprano <steve@pearwood.info> | 2016-08-24 12:48:12 +1000 |
| commit | d6ea3011c500ec2fd7793ebc593bb62a2217fa8a (patch) | |
| tree | 4124a3c4aa1354376dc42f7a7e0dcab8cd0c7c36 /Lib/statistics.py | |
| parent | e5803d9d2f47dda8b6ff69e549066d1aa68b2370 (diff) | |
| download | cpython-git-d6ea3011c500ec2fd7793ebc593bb62a2217fa8a.tar.gz | |
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.
Diffstat (limited to 'Lib/statistics.py')
| -rw-r--r-- | Lib/statistics.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Lib/statistics.py b/Lib/statistics.py index 632127af4d..40c72db0c0 100644 --- a/Lib/statistics.py +++ b/Lib/statistics.py @@ -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 |
