Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/host/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ end

@inline function u01(::Type{Float64}, u::UInt64)
# Bit-pattern construction avoids the expensive Float64(::UInt64) conversion
# and fma on consumer GPUs (where FP64 throughput is as low as 1:64). The
# low bit of the mantissa is forced set so the result is strictly in (0, 1),
# on consumer GPUs (where FP64 throughput is as low as 1:64).
# The output is uniformly sampled from the following 2^52 evenly spaced points.
# 1*2^-53, 3*2^-53, 5*2^-53 ... (2^53-1)*2^-53
# so the result is strictly in (0, 1),
# which is required by Box-Muller's log(u).
reinterpret(Float64, ((u >> 12) | 0x1) | 0x3ff0000000000000) - 1.0
reinterpret(Float64, (u >> 12) | 0x3ff0000000000000) - prevfloat(1.0)
end


Expand Down