Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add complex number support to isnan #532

Merged
merged 1 commit into from
Dec 5, 2022
Merged

Add complex number support to isnan #532

merged 1 commit into from
Dec 5, 2022

Conversation

kgryte
Copy link
Contributor

@kgryte kgryte commented Nov 28, 2022

This PR

  • adds complex number support to isnan by documenting special cases. Namely, if either component is NaN, the result should be True; otherwise, the result should be False. This follows Python, Julia, and NumPy.
  • updates the input and output array data types to be any numeric data type, not just real-valued data types.

Notes

  • Based on the guidance included in this PR, when applied in conjunction with Add complex number support to isinf #530, a complex number can be both infinite and "NaN". This may not be intuitive for users accustomed to real-valued tests, where a real value is either infinite or NaN, but not both at the same time. Accordingly, users cannot rely on simply using isnan and isinf to identify special results involving complex numbers in a mutually exclusive fashion (something which is commonly done when branching based on IEEE 754 floats).

Reference

>>> z
(inf+nanj)
>>> cmath.isnan(z)
True
>>> import numpy as np
>>> z
(inf+nanj)
>>> np.isnan(np.array([z]))
array([ True])
julia> z
inf + NaN*im

julia> isnan(z)
true

@kgryte kgryte added API change Changes to existing functions or objects in the API. topic: Complex Data Types Complex number data types. labels Nov 28, 2022
@kgryte kgryte added this to the v2022 milestone Nov 28, 2022
Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This seems consistent with existing practice, and I don't think there were any remaining concerns with that behavior. In it goes, thanks @kgryte

@rgommers rgommers merged commit 6e0c630 into main Dec 5, 2022
@rgommers rgommers deleted the cmplx-isnan branch December 5, 2022 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API change Changes to existing functions or objects in the API. topic: Complex Data Types Complex number data types.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants