Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Jan 2, 2021
1 parent 9d4a1f9 commit 734e94d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/pure/hashes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,20 @@ else:
proc hash*(x: float): Hash {.inline.} =
## Efficient hashing of floats.
var y = x + 0.0 # for denormalization
result = hash(cast[ptr Hash](addr(y))[])
when nimvm:
result = hash(cast[Hash](y))
else:
when not defined(js):
result = hash(cast[Hash](y))
else:
var res: Hash
asm """const buffer = new ArrayBuffer(8);
const floatBuffer = new Float64Array(buffer);
const uintBuffer = new BigUint64Array(buffer);
floatBuffer[0] = `y`;
`res` = uintBuffer[0];
"""
result = hash(res)

# Forward declarations before methods that hash containers. This allows
# containers to contain other containers
Expand Down

0 comments on commit 734e94d

Please sign in to comment.