You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed some inputs for which Base.Int.hash returns negative values (v0.17.1).
I was surprised and searched a bit in the doc comments. In particular, I found this in hashable_intf.ml:
(** Values returned by [hash] must be non-negative. An exception will be raised in the case that [hash] returns a negative value. *)valhash : t -> int
This made me more confident that I should indeed be surprised. Below is an expect-test I used to reproduce this:
open!Baselet%expect_test "base int hash"=(* In this test we monitor the hashes of some int values using [Base]. We note here that we would not have expected [Base.Int.hash] to sometimes return negative values, nor encounter cases where [Base.Int.hash_fold_t] applied to an empty state returns a result that differs from that of [Base.Int.hash]. *)lettesti=let h =Base.Int.hash i inlet h2 =Base.Hash.run Base.Int.hash_fold_t i in
print_s [%sexp (i : int), (h : int), (h2 : int), (h = h2 : bool)]
inList.iter ~f:test [ 0; 1; 2; 4; 5; -123456789 ];
[%expect
{|
(043166485291475858641058613066false)
(1-2609136240614377266129913994false)
(24005111014598772340462777137false)
(4-1213116315786261967607293368false)
(5-3822126110415902464648017920false)
(-123456789-547221948126359607131804527false)
|}];
()
;;
I'd be interested to learn more about this. In particular I am curious whether you consider this is a bug, or if there's some weird architecture related overflow I am hitting in the way I run the test or print the results here. Thanks!
The text was updated successfully, but these errors were encountered:
I noticed some inputs for which
Base.Int.hash
returns negative values (v0.17.1
).I was surprised and searched a bit in the doc comments. In particular, I found this in
hashable_intf.ml
:This made me more confident that I should indeed be surprised. Below is an expect-test I used to reproduce this:
I'd be interested to learn more about this. In particular I am curious whether you consider this is a bug, or if there's some weird architecture related overflow I am hitting in the way I run the test or print the results here. Thanks!
The text was updated successfully, but these errors were encountered: