mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-10 06:54:16 +00:00
hash() for floats
This commit is contained in:
@@ -122,3 +122,7 @@ proc hash*[T: tuple](x: T): THash =
|
||||
result = result !& hash(f)
|
||||
result = !$result
|
||||
|
||||
proc hash*(x: float): THash {.inline.} =
|
||||
var y = x + 1.0
|
||||
result = cast[ptr THash](addr(y))[]
|
||||
|
||||
|
||||
7
tests/run/thashes.nim
Normal file
7
tests/run/thashes.nim
Normal file
@@ -0,0 +1,7 @@
|
||||
import unittest
|
||||
import hashes
|
||||
|
||||
suite "hashes":
|
||||
suite "hashing":
|
||||
test "0.0 and -0.0 should have the same hash value":
|
||||
check hash(0.0) == hash(-0.0)
|
||||
Reference in New Issue
Block a user