gamma_inc_inv fails for low precision floats
andreasnoack opened this issue · comments
Andreas Noack commented
See the error below. The problem is that we currently promote the arguments to Float64
and then promote back but generally Float64(p) + Float64(p) != 1
when p + q == 1
if p
and q
have lower precision than Float64
and that will trigger an exception.
julia> gamma_inc_inv(1.0f0, 0.9f0, 0.1f0)
ERROR: ArgumentError: p + q must equal one but is 0.9999999776482582
Stacktrace:
[1] _gamma_inc_inv(a::Float64, p::Float64, q::Float64)
@ SpecialFunctions ~/.julia/dev/SpecialFunctions/src/gamma_inc.jl:927
[2] _gamma_inc_inv
@ ~/.julia/dev/SpecialFunctions/src/gamma_inc.jl:1017 [inlined]
[3] gamma_inc_inv(a::Float32, p::Float32, q::Float32)
@ SpecialFunctions ~/.julia/dev/SpecialFunctions/src/gamma_inc.jl:922
[4] top-level scope
@ REPL[155]:1
Maybe the solution is to change the Float16
and Float32
methods to compute 1 - Float64(min(p, q))
and verify that this number is identical to the input in the original precision before calling the Float64
method.