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

Hashtbl.hash is not compatible with (=) #5222

Closed
vicuna opened this issue Feb 9, 2011 · 2 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Feb 9, 2011

Original bug ID: 5222
Reporter: Pascal Cuoq
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2012-09-25T18:06:17Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 3.12.0
Category: ~DO NOT USE (was: OCaml general)
Related to: #5225
Monitored by: bobot till "Julien Signoles" @dbuenzli

Bug description

According to http://caml.inria.fr/pub/docs/manual-ocaml/libref/Hashtbl.html :

Hashtbl.hash x associates a positive integer to any value of any type. It is guaranteed that if x = y or Pervasives.compare x y = 0, then hash x = hash y.

But:

    Objective Caml version 3.12.0

Hashtbl.hash (+0.) ;;

  • : int = 0

Hashtbl.hash (-0.) ;;

  • : int = 128

(+0.) = (-0.) ;;

  • : bool = true

@vicuna

This comment has been minimized.

Copy link
Author

commented Mar 4, 2011

Comment author: @xavierleroy

Well spotted, thanks. Some normalization of the float is in order before hashing its bits.

@vicuna

This comment has been minimized.

Copy link
Author

commented May 29, 2011

Comment author: @xavierleroy

As part of a major overhaul of the generic hash function, fixed the +0.0/-0.0 issue, and also made sure that all NaNs hash to the same value. The code is in SVN trunk and should go into release 3.13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.