pub fn lambert_wf(
k: i16,
z_re: f32,
z_im: f32,
error_tolerance: f32,
) -> (f32, f32)Expand description
Branch k of the complex valued Lambert W function computed
on 32-bit floats with Halley’s method.
The return value is a tuple where the first element is the real part and the second element is the imaginary part.
The function iterates until the current and previous iterations are close according to the given tolerance, or it has iterated a maximum number of times. The sign of the error tolerance is ignored.
This function may be slightly less accurate close to the branch cut at -1/e, as well as close to zero on branches other than k=0.
If you know you want the principal or secondary branches where they are real-valued,
take a look at the lambert_w0f or lambert_wm1f functions instead.
They can be up to two orders of magnitude faster.
§Examples
Basic usage:
use lambert_w::lambert_wf;
// W_2(1 + 2i) with an error tolerance of at most floating point epsilon.
let w = lambert_wf(2, 1.0, 2.0, f32::EPSILON);
assert_eq!(w, (-1.6869138, 11.962631));Returns NANs if any of the components of z are infinite:
let w1 = lambert_wf(k, f32::INFINITY, z_im, eps);
let w2 = lambert_wf(k, z_re, f32::INFINITY, eps);
assert!(w1.0.is_nan() && w1.1.is_nan());
assert!(w2.0.is_nan() && w2.1.is_nan());or NAN:
let w1 = lambert_wf(k, f32::NAN, z_im, eps);
let w2 = lambert_wf(k, z_re, f32::NAN, eps);
let w3 = lambert_wf(k, z_re, z_im, f32::NAN);
assert!(w1.0.is_nan() && w1.1.is_nan());
assert!(w2.0.is_nan() && w2.1.is_nan());
assert!(w3.0.is_nan() && w3.1.is_nan());