Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #16542 #16549

Merged
merged 16 commits into from
Jan 2, 2021
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