rgsl/
dilogarithm.rs

1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5use crate::{sys, types, Value};
6use std::mem::MaybeUninit;
7
8/// These routines compute the dilogarithm for a real argument. In Lewin’s notation this is Li_2(x), the real part of the dilogarithm of a real x.
9/// It is defined by the integral representation Li_2(x) = - \Re \int_0^x ds \log(1-s) / s. Note that \Im(Li_2(x)) = 0 for x <= 1, and -\pi\log(x) for x > 1.
10///
11/// Note that Abramowitz & Stegun refer to the Spence integral S(x)=Li_2(1-x) as the dilogarithm rather than Li_2(x).
12#[doc(alias = "gsl_sf_dilog")]
13pub fn dilog(x: f64) -> f64 {
14    unsafe { sys::gsl_sf_dilog(x) }
15}
16
17/// These routines compute the dilogarithm for a real argument. In Lewin’s notation this is Li_2(x), the real part of the dilogarithm of a real x.
18/// It is defined by the integral representation Li_2(x) = - \Re \int_0^x ds \log(1-s) / s. Note that \Im(Li_2(x)) = 0 for x <= 1, and -\pi\log(x) for x > 1.
19///
20/// Note that Abramowitz & Stegun refer to the Spence integral S(x)=Li_2(1-x) as the dilogarithm rather than Li_2(x).
21#[doc(alias = "gsl_sf_dilog_e")]
22pub fn dilog_e(x: f64) -> Result<types::Result, Value> {
23    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
24    let ret = unsafe { sys::gsl_sf_dilog_e(x, result.as_mut_ptr()) };
25
26    result_handler!(ret, unsafe { result.assume_init() }.into())
27}
28
29/// This function computes the full complex-valued dilogarithm for the complex argument z = r \exp(i \theta).
30/// The real and imaginary parts of the result are returned in result_re, result_im.
31#[doc(alias = "gsl_sf_complex_dilog_e")]
32pub fn complex_dilog_e(r: f64, theta: f64) -> Result<(types::Result, types::Result), Value> {
33    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
34    let mut result_im = MaybeUninit::<sys::gsl_sf_result>::uninit();
35    let ret = unsafe {
36        sys::gsl_sf_complex_dilog_e(r, theta, result.as_mut_ptr(), result_im.as_mut_ptr())
37    };
38
39    result_handler!(
40        ret,
41        (
42            unsafe { result.assume_init() }.into(),
43            unsafe { result_im.assume_init() }.into(),
44        )
45    )
46}