rgsl/lambert_w.rs
1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5/*!
6Lambert’s W functions, W(x), are defined to be solutions of the equation W(x) \exp(W(x)) = x. This function has multiple branches for x < 0; however, it has only two real-valued branches.
7We define W_0(x) to be the principal branch, where W > -1 for x < 0, and W_{-1}(x) to be the other real branch, where W < -1 for x < 0.
8!*/
9
10use crate::{types, Value};
11use std::mem::MaybeUninit;
12
13/// This computes the principal branch of the Lambert W function, W_0(x).
14#[doc(alias = "gsl_sf_lambert_W0")]
15pub fn lambert_W0(x: f64) -> f64 {
16 unsafe { sys::gsl_sf_lambert_W0(x) }
17}
18
19/// This computes the principal branch of the Lambert W function, W_0(x).
20#[doc(alias = "gsl_sf_lambert_W0_e")]
21pub fn lambert_W0_e(x: f64) -> Result<types::Result, Value> {
22 let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
23 let ret = unsafe { sys::gsl_sf_lambert_W0_e(x, result.as_mut_ptr()) };
24
25 result_handler!(ret, unsafe { result.assume_init() }.into())
26}
27
28/// This computes the secondary real-valued branch of the Lambert W function, W_{-1}(x).
29#[doc(alias = "gsl_sf_lambert_Wm1")]
30pub fn lambert_Wm1(x: f64) -> f64 {
31 unsafe { sys::gsl_sf_lambert_Wm1(x) }
32}
33
34/// This computes the secondary real-valued branch of the Lambert W function, W_{-1}(x).
35#[doc(alias = "gsl_sf_lambert_Wm1_e")]
36pub fn lambert_Wm1_e(x: f64) -> Result<types::Result, Value> {
37 let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
38 let ret = unsafe { sys::gsl_sf_lambert_Wm1_e(x, result.as_mut_ptr()) };
39
40 result_handler!(ret, unsafe { result.assume_init() }.into())
41}