FLINT3.7.0-dev

d_lambertw

Synopsis#include <flint/double_extras.h>
double d_lambertw(double x)source

Returns the principal branch W0(x)W_0(x) of the Lambert W function, the solution w≥−1w \ge -1 of wew=xw e^w = x. Returns NaN for x<−1/ex < -1/e, where the solution is complex, and for x=−∞x = -\infty; returns xx itself for x=0x = 0, x=+∞x = +\infty and NaN.

Close to zero, the result is x−x2x - x^2 (for ∣x∣<10−9|x| < 10^{-9}) or a rational approximation. Close to the branch point −1/e-1/e, it is a polynomial in x+1/e\sqrt{x + 1/e}, where x+1/ex + 1/e is computed with a correction term for the rounding of 1/e1/e (the most negative double in the domain is −6627126856707895⋅2−54-6627126856707895 \cdot 2^{-54}). Elsewhere, an initial value from a piecewise rational approximation, or for x>40x > 40 from the asymptotic expansion in L1=log⁡xL_1 = \log x and L2=log⁡log⁡xL_2 = \log \log x [CGHJK1996], is refined by one or two steps of Halley's method, rescaled to avoid overflow of ewe^w near the top of the exponent range.

A test of 10710^7 random inputs showed a maximum relative error below 0.95⋅2−520.95 \cdot 2^{-52} for positive xx; for negative xx the error is larger, up to about 10⋅2−5210 \cdot 2^{-52} close to −1/e-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
Cite this page

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).