The Lambert W function has two partially real branches: the
principal branch (k = 0) is real for real z>-1/e, and the
k=-1 branch is real for -1/e<z<0. All branches except
k=0 have a logarithmic singularity at z=0.

Possible issues

The evaluation can become inaccurate very close to the branch point
at -1/e. In some corner cases, lambertw might currently
fail to converge, or can end up on the wrong branch.

Algorithm

Halley’s iteration is used to invert w*exp(w), using a first-order
asymptotic approximation (O(log(w)) or O(w)) as the initial estimate.

The definition, implementation and choice of branches is based on [R243].