JuliaMath / JuliaMath/LambertW.jl

MethodError caused by implementation of complex rationals in a small region (function fails for -0.6 + 0.0*im < z < -0.4 + 0.0*im)

Open
#35 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
24
Forks
16
PR merge metrics
No merged PRs in 30d

Description

Hi,

Thanks for the package, I use it a lot.

I've noticed an issue with the implementation. There is a small region of complex floating-point arguments which trigger this line (line 151) in the case structure:-
```
w = abs(z+ 1//2) < 1//10 ? imag(z) > 0 ? complex(pointseven, pointseven) : complex(pointseven, -pointseven) : z
```
If `w` is assigned either `complex(pointseven, pointseven)` or `complex(pointseven, -pointseven)`, then the root finding raises a MethodError, because of the function signature (line 168)
```
function lambertw_root_finding(z::T, x0::T, maxits) where T <: Number
```
which expects `z` and `x0` to have the same type, but it will get `z::ComplexF64` and `x0::Complex{Rational{Int64}}`.

On the real line this corresponds to approximately -0.6 < z -0.4, and it doesn't take much of an imaginary part before the problematic line isn't triggered, which may explain why no-one's spotted it until now!

Thanks

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.