Skip to content

hashCode of a double is very trivial #26273

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
filiph opened this issue Apr 15, 2016 · 1 comment
Closed

hashCode of a double is very trivial #26273

filiph opened this issue Apr 15, 2016 · 1 comment
Labels
closed-duplicate Closed in favor of an existing report

Comments

@filiph
Copy link
Contributor

filiph commented Apr 15, 2016

Not sure if this is intended but calling number.hashCode is equivalent to number.toInt().

class _Double extends _Num implements double {
  // ...

  int get _identityHashCode {
    if (isNaN || isInfinite) return 0;
    return toInt();
  }
}

This of course means that 3.14, 3.14159 and 3.9 all have the same hashCode. It gets even more confusing when you're trying to do hashCodes of numbers that are close to zero because 0 suggests some kind of other problem.

It would be useful to have something like Java's Double.hashCode().

@Fox32
Copy link

Fox32 commented Apr 15, 2016

Duplicate of #2884

@kevmoo kevmoo added the closed-duplicate Closed in favor of an existing report label Apr 17, 2016
@kevmoo kevmoo closed this as completed Apr 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

3 participants