File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -118,13 +118,7 @@ proc hash*[T: SomeNumber | Ordinal | char](x: T): Hash {.inline.} =
118118 # bugfix: the previous code was using `x = x + 1.0` (presumably for
119119 # handling negative 0), however this leads to collisions for small x due
120120 # to FP finite precision.
121- let x: BiggestInt =
122- if x == 0 : 0 .BiggestInt
123- else :
124- when sizeof (BiggestInt ) == sizeof (T):
125- cast [BiggestInt ](x)
126- else : # for nimvm
127- cast [int32 ](x).BiggestInt
121+ let x = cast [BiggestInt ](x + T (0 ))
128122 else :
129123 let x = x.BiggestInt
130124 hashBiggestInt (x)
Original file line number Diff line number Diff line change @@ -15,3 +15,10 @@ suite "hashes":
1515 test " 0.0 and -0.0 should have the same hash value" :
1616 var dummy = 0.0
1717 check hash (dummy) == hash (- dummy)
18+ check hash (0.0 ) == hash (- 0.0 )
19+ check hash (0.0 f) == hash (- 0.0 f)
20+ let h1 = hash (0.0 )
21+ const h2 = hash (0.0 )
22+ const h3 = hash (- 0.0 )
23+ check h1 == h2
24+ check h1 == h3
You can’t perform that action at this time.
0 commit comments