Skip to content

Commit 51458e8

Browse files
committed
faster OpenOpen for IEEEFloat
1 parent 6e24f5d commit 51458e8

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/sampling.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ rand(r::AbstractRNG, sp::SamplerSimple{OpenOpen01{T}}) where {T} =
5252
x != zero(T) && return x
5353
end
5454

55+
# optimizations (TODO: optimize for BigFloat too)
56+
57+
rand(r::AbstractRNG, sp::SamplerSimple{OpenOpen01{Float64}}) =
58+
reinterpret(Float64, reinterpret(UInt64, rand(r, sp.data)) | 0x0000000000000001)
59+
60+
rand(r::AbstractRNG, sp::SamplerSimple{OpenOpen01{Float32}}) =
61+
reinterpret(Float32, reinterpret(UInt32, rand(r, sp.data)) | 0x00000001)
62+
63+
rand(r::AbstractRNG, sp::SamplerSimple{OpenOpen01{Float16}}) =
64+
reinterpret(Float16, reinterpret(UInt16, rand(r, sp.data)) | 0x0001)
65+
5566
# prevfloat(T(2)) - 1 for IEEEFloat
5667
upper01(::Type{Float64}) = 0.9999999999999998
5768
upper01(::Type{Float32}) = 0.9999999f0

0 commit comments

Comments
 (0)