diff options
author | Simon Hafner <hafnersimon@gmail.com> | 2012-09-08 15:15:28 -0500 |
---|---|---|
committer | Simon Hafner <hafnersimon@gmail.com> | 2012-09-08 15:15:28 -0500 |
commit | 1852c0548c23974e1d5f34f2e9d49ff63e7bc267 (patch) | |
tree | 04865e70f8b81b36160a304f73c98025b51b7cb3 | |
parent | e9bbc7235dc017a97fdc831efdaacb5325984d18 (diff) | |
download | Nim-1852c0548c23974e1d5f34f2e9d49ff63e7bc267.tar.gz |
hash() for floats
-rwxr-xr-x | lib/pure/hashes.nim | 4 | ||||
-rw-r--r-- | tests/run/thashes.nim | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/pure/hashes.nim b/lib/pure/hashes.nim index 9c086c675..ac6d3c3ce 100755 --- a/lib/pure/hashes.nim +++ b/lib/pure/hashes.nim @@ -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))[] + diff --git a/tests/run/thashes.nim b/tests/run/thashes.nim new file mode 100644 index 000000000..2b418c4cd --- /dev/null +++ b/tests/run/thashes.nim @@ -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) \ No newline at end of file |