Skip to content

Array.indexOf broken for Double.NaN #3291

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

Closed
scabug opened this issue Apr 14, 2010 · 3 comments
Closed

Array.indexOf broken for Double.NaN #3291

scabug opened this issue Apr 14, 2010 · 3 comments

Comments

@scabug
Copy link

scabug commented Apr 14, 2010

scala> Array(Double.NaN) indexOf Double.NaN
res0: Int = -1

scala>

Actual: -1, Expected: 0

Scala version 2.8.0.r21376-b20100408020204 (Java HotSpot(TM) Client VM, Java 1.6.0_18).

@scabug
Copy link
Author

scabug commented Apr 14, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3291?orig=1
Reporter: Joa Ebert (joa)

@scabug
Copy link
Author

scabug commented Apr 14, 2010

Joa Ebert (joa) said:
Double.NaN == Double.NaN is also false.

@scabug
Copy link
Author

scabug commented Apr 14, 2010

@paulp said:
Double.NaN == Double.NaN is supposed to be false. (It's false in java too.) There is a problem with NaN, but you're not illustrating it here, and I don't think we can fix it anyway. That is that java decided to make the boxed NaNs return true on equals while keeping the primitive == false. Since we unified those worlds we can't satisfy both. See #2598.

If you really want to find NaN you need to look for it differently.

scala> Array(Double.NaN) indexWhere (_.isNaN)
res0: Int = 0

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

1 participant