d_lambertw
#include <flint/double_extras.h>double d_lambertw(double x)sourceReturns the principal branch W_0(x) of the Lambert W function, the solution w \ge -1 of w e^w = x. Returns NaN for x < -1/e, where the solution is complex, and for x = -\infty; returns x itself for x = 0, x = +\infty and NaN.
Close to zero, the result is x - x^2 (for |x| < 10^{-9}) or a rational approximation. Close to the branch point -1/e, it is a polynomial in \sqrt{x + 1/e}, where x + 1/e is computed with a correction term for the rounding of 1/e (the most negative double in the domain is -6627126856707895 \cdot 2^{-54}). Elsewhere, an initial value from a piecewise rational approximation, or for x > 40 from the asymptotic expansion in L_1 = \log x and L_2 = \log \log x [CGHJK1996], is refined by one or two steps of Halley's method, rescaled to avoid overflow of e^w near the top of the exponent range.
A test of 10^7 random inputs showed a maximum relative error below 0.95 \cdot 2^{-52} for positive x; for negative x the error is larger, up to about 10 \cdot 2^{-52} close to -1/e. 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-10-20).
@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-10-20}
}