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

Eq trait implementation on Number #183

Open
timothee-haudebourg opened this issue Mar 30, 2020 · 4 comments
Open

Eq trait implementation on Number #183

timothee-haudebourg opened this issue Mar 30, 2020 · 4 comments

Comments

@timothee-haudebourg
Copy link

I'm wondering why Eq is not implemented for the Number struct. At first, I thought it was because Number can also represent NaN for which we usually expect that NaN != NaN. However a rapid glance at the implementation showed me that in the implementation of PartialEq, we have NaN == NaN.

Having Eq would be useful to use Number or even JsonValue in containers like HashSet.

Also why do you need to represent NaN in Number? As far as I know there is no NaN in JSON, right?

@timothee-haudebourg
Copy link
Author

A Hash trait implementation would also be nice.

@PurpleMyst
Copy link

PurpleMyst commented May 6, 2020

Might be interesting to use noisy_float or something.

In JavaScript, JSON.stringify(NaN) returns null. I think having NaN at all near JSON is just an error waiting to happen.

@PurpleMyst
Copy link

If the NaN issue is cleared up I'd love to implement this, it seems pretty simple.

@maciejhirsz
Copy link
Owner

NaN on Number is here purely for conversions from f64. I'm okay with it being removed (along with From) as long as there is a conversion from f64 for JsonValue that produces Null for NaN floats (since that seems to be the expected behavior).

@PurpleMyst with the stuff mentioned above, if you want to submit a PR, go for it :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants