From 1852c0548c23974e1d5f34f2e9d49ff63e7bc267 Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Sat, 8 Sep 2012 15:15:28 -0500 Subject: [PATCH 1/3] hash() for floats --- lib/pure/hashes.nim | 4 ++++ tests/run/thashes.nim | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/run/thashes.nim diff --git a/lib/pure/hashes.nim b/lib/pure/hashes.nim index 9c086c6757..ac6d3c3ced 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 0000000000..2b418c4cdc --- /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 From 214b727a7525924f37fc7c917c34beae394f9ef1 Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Sat, 8 Sep 2012 15:16:56 -0500 Subject: [PATCH 2/3] Issue #197 has been solved --- tests/run/tmath.nim | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/run/tmath.nim b/tests/run/tmath.nim index 65124306eb..a86a3b84ce 100644 --- a/tests/run/tmath.nim +++ b/tests/run/tmath.nim @@ -25,14 +25,12 @@ suite "random int": check rand >= 100 suite "random float": - # Enable this once #197 has been resolved - # test "there might be some randomness": - # var set = initSet[float](128) - # for i in 1..10: - # for j in 1..10: - # randomize() - # incl(set, random(1.0)) - # check len(set) == 100 + test "there might be some randomness": + var set = initSet[float](128) + randomize() + for i in 1..100: + incl(set, random(1.0)) + check len(set) == 100 test "single number bounds work": randomize() var rand: float From 664bd55e852f237dec03913accedcc5291863048 Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Sat, 8 Sep 2012 15:54:00 -0500 Subject: [PATCH 3/3] real test now --- tests/run/thashes.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/run/thashes.nim b/tests/run/thashes.nim index 2b418c4cdc..c442b43fba 100644 --- a/tests/run/thashes.nim +++ b/tests/run/thashes.nim @@ -4,4 +4,5 @@ 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 + var dummy = 0.0 + check hash(dummy) == hash(-dummy)