diff options
author | Matti Picus <matti.picus@gmail.com> | 2021-11-17 19:04:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-17 19:04:07 +0200 |
commit | 3376e08662a950d9bf89a462b2e8de5a135665c4 (patch) | |
tree | 0e0ba68b466477f4e2212b90340662af76fa3367 | |
parent | 7e94e1eac1efcc40c3e82a98a4acbf5bb5eb25c1 (diff) | |
parent | 8cb5466d55dec6b63ed4e58ce14a369adb41b7ca (diff) | |
download | numpy-3376e08662a950d9bf89a462b2e8de5a135665c4.tar.gz |
Merge pull request #20244 from MuhammadMotawe/clarify-sqrt-behavior
DOC: Clarify behavior of ``np.lib.scimath.sqrt`` apropos -0.0
-rw-r--r-- | numpy/core/code_generators/ufunc_docstrings.py | 1 | ||||
-rw-r--r-- | numpy/lib/scimath.py | 9 |
2 files changed, 10 insertions, 0 deletions
diff --git a/numpy/core/code_generators/ufunc_docstrings.py b/numpy/core/code_generators/ufunc_docstrings.py index c9be94569..cd584eea7 100644 --- a/numpy/core/code_generators/ufunc_docstrings.py +++ b/numpy/core/code_generators/ufunc_docstrings.py @@ -3827,6 +3827,7 @@ add_newdoc('numpy.core.umath', 'sqrt', -------- lib.scimath.sqrt A version which returns complex numbers when given negative reals. + Note: 0.0 and -0.0 are handled differently for complex inputs. Notes ----- diff --git a/numpy/lib/scimath.py b/numpy/lib/scimath.py index 308f1328b..b7ef0d710 100644 --- a/numpy/lib/scimath.py +++ b/numpy/lib/scimath.py @@ -234,6 +234,15 @@ def sqrt(x): >>> np.emath.sqrt([-1,4]) array([0.+1.j, 2.+0.j]) + Different results are expected because: + floating point 0.0 and -0.0 are distinct. + + For more control, explicitly use complex() as follows: + + >>> np.emath.sqrt(complex(-4.0, 0.0)) + 2j + >>> np.emath.sqrt(complex(-4.0, -0.0)) + -2j """ x = _fix_real_lt_zero(x) return nx.sqrt(x) |