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

Poisson rand InexactError for extremely large parameter values #821

Open
simonbyrne opened this issue Jan 24, 2019 · 4 comments
Open

Poisson rand InexactError for extremely large parameter values #821

simonbyrne opened this issue Jan 24, 2019 · 4 comments
Labels

Comments

@simonbyrne
Copy link
Member

julia> rand(Poisson(1e20))
ERROR: InexactError: Int64(Int64, 9.999999997262139e19)
Stacktrace:
 [1] Type at ./float.jl:700 [inlined]
 [2] convert at ./number.jl:7 [inlined]
 [3] rand(::Poisson{Float64}) at /Users/simon/.julia/packages/Distributions/WHjOk/src/univariate/discrete/poisson.jl:89
 [4] top-level scope at none:0

Note that the underlying Rmath library actually works in terms of Float64s (see JuliaStats/Rmath-julia#11).

@mschauer
Copy link
Member

I think it only fails if the return value is actually outside the range of Int:

julia> rand(Poisson(float(typemax(Int64))))
9223372034018728960

julia> rand(Poisson(float(typemax(Int64))))
9223372033786713088

julia> rand(Poisson(float(typemax(Int64))))
ERROR: InexactError: Int64(Int64, 9.223372040475427e18)

@mschauer
Copy link
Member

PS: Someday somewhere in some parallel universe a rand(Poisson(1.0)) will fail with overflow.

@simonbyrne
Copy link
Member Author

I guess it would be useful to have a rand(::Type{Float64}, d::Poisson) method that didn't do the conversion to Int.

@CameronBieganek
Copy link

It would be nice if this could return a better error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants