summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--byterun/hash.c2
-rw-r--r--testsuite/tests/lib-num/end_test.reference2
-rw-r--r--testsuite/tests/lib-num/test_big_ints.ml20
3 files changed, 23 insertions, 1 deletions
diff --git a/byterun/hash.c b/byterun/hash.c
index d8f26f8a8..494cf28b6 100644
--- a/byterun/hash.c
+++ b/byterun/hash.c
@@ -210,7 +210,7 @@ CAMLprim value caml_hash(value count, value limit, value seed, value obj)
num--;
}
else if (Is_in_value_area(v)) {
- switch (Tag_val(obj)) {
+ switch (Tag_val(v)) {
case String_tag:
h = caml_hash_mix_string(h, v);
num--;
diff --git a/testsuite/tests/lib-num/end_test.reference b/testsuite/tests/lib-num/end_test.reference
index 8a78296e4..8e7ac4b6c 100644
--- a/testsuite/tests/lib-num/end_test.reference
+++ b/testsuite/tests/lib-num/end_test.reference
@@ -83,6 +83,8 @@ shift_right_towards_zero_big_int
1... 2...
extract_big_int
1... 2... 3... 4... 5... 6...
+hashing of big integers
+ 1... 2... 3... 4... 5... 6...
create_ratio
1... 2... 3... 4... 5... 6... 7... 8...
create_normalized_ratio
diff --git a/testsuite/tests/lib-num/test_big_ints.ml b/testsuite/tests/lib-num/test_big_ints.ml
index 46ffc5972..badc52160 100644
--- a/testsuite/tests/lib-num/test_big_ints.ml
+++ b/testsuite/tests/lib-num/test_big_ints.ml
@@ -922,3 +922,23 @@ test 5 eq_big_int
test 6 eq_big_int
(extract_big_int (big_int_of_int (-1)) 2048 254,
zero_big_int);;
+
+testing_function "hashing of big integers";;
+
+test 1 eq_int (Hashtbl.hash zero_big_int,
+ 955772237);;
+test 2 eq_int (Hashtbl.hash unit_big_int,
+ 992063522);;
+test 3 eq_int (Hashtbl.hash (minus_big_int unit_big_int),
+ 161678167);;
+test 4 eq_int (Hashtbl.hash (big_int_of_string "123456789123456789"),
+ 755417385);;
+test 5 eq_int (Hashtbl.hash (sub_big_int
+ (big_int_of_string "123456789123456789")
+ (big_int_of_string "123456789123456789")),
+ 955772237);;
+test 6 eq_int (Hashtbl.hash (sub_big_int
+ (big_int_of_string "123456789123456789")
+ (big_int_of_string "123456789123456788")),
+ 992063522);;
+