1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
use num::complex::Complex;
/// Provides the 0-th order polylogarithm function `li0()` of a
/// number of type `T`.
pub trait Li0<T> {
fn li0(&self) -> T;
}
impl Li0<f64> for f64 {
/// Returns the real 0th order polylogarithm of a real number of
/// type `f64`.
///
/// # Example:
/// ```
/// use polylog::Li0;
///
/// assert!((2.0_f64.li0() + 2.0_f64).abs() < std::f64::EPSILON);
/// ```
fn li0(&self) -> f64 {
if *self == 0.0 {
*self
} else {
self/(1.0 - self)
}
}
}
impl Li0<Complex<f64>> for Complex<f64> {
/// Returns the 0th order polylogarithm of a complex number of
/// type `Complex<f64>`.
///
/// # Example:
/// ```
/// use num::complex::Complex;
/// use polylog::Li0;
///
/// assert!((Complex::new(1.0_f64, 1.0_f64).li0() - Complex::new(-1.0_f64, 1.0_f64)).norm() < std::f64::EPSILON);
/// ```
fn li0(&self) -> Complex<f64> {
if *self == Complex::new(0.0, 0.0) {
*self
} else {
self/(1.0 - self)
}
}
}