JuliaMath / JuliaMath/FunctionZeros.jl
Integer overflow causes incorrect output from bessel_deriv_zero_asymptotic
- Dominant language
- Julia
- Stars
- 9
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
Here is an example of erroneous output when `nu isa Int` but correct output when `nu isa Float64` of the same value:
```
julia> besselj_deriv_zero(37, 1)
0.0
julia> besselj_deriv_zero(37.0, 1)
39.71488992674072
```
The problem can be traced to integer overflow when computing [the numerator of variable `t4` ](https://github.com/JuliaMath/FunctionZeros.jl/blob/4bf2374290729133adcf80de4b149a9232025f85/src/FunctionZeros.jl#L211) in function `bessel_deriv_zero_asymptotic`. A similar problem with overflow occurs when computing [the numerator of variable t4](https://github.com/JuliaMath/FunctionZeros.jl/blob/4bf2374290729133adcf80de4b149a9232025f85/src/FunctionZeros.jl#L73) in function `bessel_zero_asymptotic`, though it doesn't manifest until larger values of `nu` are used:
```
julia> FunctionZeros.besselj_zero_asymptotic(87, 1)
103.5246288334123
julia> FunctionZeros.besselj_zero_asymptotic(87.0, 1)
100.99682928339313
```
This error doesn't propagate out of `besselj_zero` because the erroneous asymptotic value is still close enough to the true zero for the latter to be found by the rootfinder.
I think that the solution is to promote `nu` to `float(abs(nu_in))` whenever `nu_in` is an `Integer`. I'll work on a PR that implements this.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.