Skip to content

Commit

Permalink
fix rand underflow issue
Browse files Browse the repository at this point in the history
dzhang314 committed Sep 8, 2024
1 parent c996294 commit 8b096c6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/MultiFloats.jl
Original file line number Diff line number Diff line change
@@ -1432,6 +1432,9 @@ import Random: rand


@inline function _rand_f64(rng::AbstractRNG, k::Int)
if k < exponent(floatmin(Float64))
return zero(Float64)
end
expnt = reinterpret(UInt64,
exponent(floatmax(Float64)) + k) << (precision(Float64) - 1)
mntsa = rand(rng, UInt52())
@@ -1440,6 +1443,9 @@ end


@inline function _rand_sf64(rng::AbstractRNG, k::Int)
if k < exponent(floatmin(Float64))
return zero(Float64)
end
expnt = reinterpret(UInt64,
exponent(floatmax(Float64)) + k) << (precision(Float64) - 1)
mntsa = rand(rng, UInt64) & 0x800FFFFFFFFFFFFF

0 comments on commit 8b096c6

Please sign in to comment.