Skip to content

Commit

Permalink
Merge pull request #53 from org-arl/patch-randexp
Browse files Browse the repository at this point in the history
fix: infinite return value
  • Loading branch information
ymtoo authored Dec 29, 2024
2 parents 6776f1a + 2331de7 commit 790607d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AlphaStableDistributions"
uuid = "f20549b4-2d50-407f-863c-cdd202ba59a3"
authors = ["Fredrik Bagge Carlson", "Too Yuen Min"]
version = "1.1.8"
version = "1.1.9"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
2 changes: 1 addition & 1 deletion src/AlphaStableDistributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function Base.rand(rng::AbstractRNG, d::AlphaStable{T}) where {T<:AbstractFloat}
if α == one(T) && β == zero(T)
return loc + sc * tan(ϕ)
end
w = -log(rand(rng, T))
w = randexp(rng) # exponential random variable with mean 1
α == 2 && (return loc + 2*sc*sqrt(w)*sin(ϕ))
β == zero(T) && (return loc + sc * ((cos((one(T)-α)*ϕ) / w)^(one(T)/α - one(T)) * sin* ϕ) / cos(ϕ)^(one(T)/α)))
cosϕ = cos(ϕ)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ end
end
s = rand(rng, d1, 10^6)
@test eltype(s) == sampletype
@test any(isinf.(s)) == false

d2 = fit(stabletype, s)
@test typeof(d2.α) == sampletype
Expand Down

0 comments on commit 790607d

Please sign in to comment.