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

[C++] I know NAN != NAN but shouldn't literal(NAN) == literal(NAN)? #33990

Closed
westonpace opened this issue Feb 1, 2023 · 4 comments
Closed
Assignees
Labels
Component: C++ Type: usage Issue is a user question
Milestone

Comments

@westonpace
Copy link
Member

Describe the usage question you have. Please include as many useful details as possible.

I'm pretty sure of this but wanted a sanity test. Also, should literal(quiet_NAN) == literal(signaling_NAN)? My intuition is "no".

Or...more concretely...should these test cases pass?

  // This currently fails
  EXPECT_EQ(literal(std::numeric_limits<double>::quiet_NaN()),
            literal(std::numeric_limits<double>::quiet_NaN()));
  // These currently pass
  EXPECT_NE(literal(std::numeric_limits<double>::quiet_NaN()),
            literal(std::numeric_limits<double>::signaling_NaN()));
  EXPECT_NE(literal(std::numeric_limits<double>::quiet_NaN()),
            literal(std::numeric_limits<float>::quiet_NaN()));

If the answer is "yes, those two expressions are equivalent" then I can fix it in #15180 . I already have a fix but wanted to confirm my understanding.

Component(s)

C++

@westonpace westonpace added Component: C++ Type: usage Issue is a user question labels Feb 1, 2023
@westonpace
Copy link
Member Author

Actually, I can't find a good way to test if a NaN is a quiet nan or a signalling NaN so now I'm tempted to say literal(quiet_NaN) == literal(signal_NaN) as well.

@westonpace
Copy link
Member Author

Ah, I can use issignaling which is in <cmath> but has no c++ equivalent.

@bkietz
Copy link
Member

bkietz commented Feb 1, 2023

I think that we don't need to support signalling nans. Quiet nans may be produced by floating point expressions with invalid arguments, but signalling nans can only be produced explicitly- which is not functionality I think we'd find valuable. For our purposes, I don't think we need to check for signalling nans.

I do think that literal(nan) == literal(nan) should be true- as you say those two expressions are equivalent. I think just to disambiguate the situation the unit test should also assert that equal(literal(nan), literal(nan)) evaluates to false and clarify why that difference exists with a comment

@jorisvandenbossche
Copy link
Member

This was closed by #15180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: C++ Type: usage Issue is a user question
Projects
None yet
Development

No branches or pull requests

3 participants