Skip to content

Commit

Permalink
Move trait tests to impls
Browse files Browse the repository at this point in the history
  • Loading branch information
JSorngard committed Oct 5, 2024
1 parent 730193b commit 1b0dc01
Showing 1 changed file with 23 additions and 32 deletions.
55 changes: 23 additions & 32 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,38 +366,6 @@ pub fn lambert_wm1f(z: f32) -> f32 {
}

/// Enables evaluation of the principal and secondary branches of the Lambert W function with the types that implement this trait.
///
/// # Examples
///
#[cfg_attr(
feature = "24bits",
doc = r#"
```
# use approx::assert_abs_diff_eq;
use lambert_w::LambertW;
use core::f32::consts::LN_10;
let z = 10.0 * LN_10;
assert_abs_diff_eq!(z.lambert_w0(), LN_10, epsilon = 1e-6);
```
"#
)]
///
#[cfg_attr(
feature = "50bits",
doc = r#"
```
# use approx::assert_abs_diff_eq;
use lambert_w::LambertW;
use core::f64::consts::E;
let z = E.powf(1.0 + E);
assert_abs_diff_eq!(z.lambert_w0(), E);
```
"#
)]
pub trait LambertW {
/// The type returned by the Lambert W functions when acting on a value of type `Self`.
type Output;
Expand All @@ -417,6 +385,17 @@ impl LambertW for f32 {
/// Evaluated with the approximation with 24-bits of accuracy from the paper, but on 32-bit floats.
///
/// Delegates to the [`lambert_w0f`] function.
///
/// # Example
/// ```
/// # use approx::assert_abs_diff_eq;
/// use lambert_w::LambertW;
/// use core::f32::consts::LN_10;
///
/// let z = 10.0 * LN_10;
///
/// assert_abs_diff_eq!(z.lambert_w0(), LN_10, epsilon = 1e-6);
/// ```
#[inline]
fn lambert_w0(self) -> Self::Output {
lambert_w0f(self)
Expand All @@ -438,6 +417,18 @@ impl LambertW for f64 {
/// The principal branch of the Lambert W function evaluated to 50 bits of accuracy.
///
/// Delegates to the [`lambert_w0`] function.
///
/// # Example
///
/// ```
/// # use approx::assert_abs_diff_eq;
/// use lambert_w::LambertW;
/// use core::f64::consts::E;
///
/// let z = E.powf(1.0 + E);
///
/// assert_abs_diff_eq!(z.lambert_w0(), E, epsilon = 1e-15);
/// ```
#[inline]
fn lambert_w0(self) -> Self::Output {
lambert_w0(self)
Expand Down

0 comments on commit 1b0dc01

Please sign in to comment.