Skip to content

Integer overflow causes incorrect output from bessel_deriv_zero_asymptotic #27

@simonp0420

Description

@simonp0420

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 in function bessel_deriv_zero_asymptotic. A similar problem with overflow occurs when computing the numerator of variable t4 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions