d_lambertw
#include <flint/double_extras.h>double d_lambertw(double x)sourceReturns the principal branch of the Lambert W function, the solution of . Returns NaN for , where the solution is complex, and for ; returns itself for , and NaN.
Close to zero, the result is (for ) or a rational approximation. Close to the branch point , it is a polynomial in , where is computed with a correction term for the rounding of (the most negative double in the domain is ). Elsewhere, an initial value from a piecewise rational approximation, or for from the asymptotic expansion in and [CGHJK1996], is refined by one or two steps of Halley's method, rescaled to avoid overflow of near the top of the exponent range.
A test of random inputs showed a maximum relative error below for positive ; for negative the error is larger, up to about close to . The accuracy depends on the compiler flags and on the system exp and log. For a rigorous enclosure at any precision, use arb_lambertw.
References#
- [CGHJK1996] R. M. Corless, G. H. Gonnet, D. E. Hare, D. J. Jeffrey and D. E. Knuth, "On the Lambert W function", Advances in Computational Mathematics, 5(1) (1996), 329-359
The FLINT team, “d_lambertw (double_extras.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/double_extras/d_lambertw.html (generated 2026-11-02).
@misc{flint-doc-double-extras-d-lambertw,
author = {{The FLINT team}},
title = {{d\_lambertw (double\_extras.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/double_extras/d_lambertw.html},
note = {Generated 2026-11-02}
}