Skip to content

Commit

Permalink
Explain macro once, then have cleaner doc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
JSorngard committed Jul 29, 2024
1 parent 4a615e3 commit bae0090
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
16 changes: 6 additions & 10 deletions src/accurate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ use super::Z0;
///
/// Basic usage:
/// ```
/// # use approx::assert_abs_diff_eq;
/// use lambert_w::accurate::lambert_w_0;
///
/// use approx::assert_abs_diff_eq;
/// use core::f64::consts::PI;
/// let w = lambert_w_0(1.0).unwrap();
///
/// let w = lambert_w_0(PI).unwrap();
///
/// assert_abs_diff_eq!(w, 1.0736581947961492);
/// assert_abs_diff_eq!(w, 0.5671432904097838);
/// ```
/// Arguments smaller than -1/e (≈ -0.36787944117144233) result in `None`:
/// ```
Expand All @@ -42,14 +40,12 @@ pub fn lambert_w_0(z: f64) -> Option<f64> {
///
/// Basic usage:
/// ```
/// # use approx::assert_abs_diff_eq;
/// use lambert_w::accurate::lambert_w_m1;
///
/// use approx::assert_abs_diff_eq;
/// use core::f64::consts::PI;
///
/// let w = lambert_w_m1(-1.0/PI).unwrap();
/// let w = lambert_w_m1(-f64::ln(2.0) / 2.0).unwrap();
///
/// assert_abs_diff_eq!(w, -1.6385284199703634);
/// assert_abs_diff_eq!(w, -f64::ln(4.0));
/// ```
/// Arguments smaller than -1/e (≈ -0.36787944117144233) or larger than 0 result in `None`:
/// ```
Expand Down
16 changes: 6 additions & 10 deletions src/fast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ use swm1::swm1;
///
/// Basic usage:
/// ```
/// # use approx::assert_abs_diff_eq;
/// use lambert_w::fast::lambert_w_0;
///
/// use approx::assert_abs_diff_eq;
/// use core::f64::consts::PI;
/// let w = lambert_w_0(1.0).unwrap();
///
/// let w = lambert_w_0(PI).unwrap();
///
/// assert_abs_diff_eq!(w, 1.0736581947961492, epsilon = 1e-7);
/// assert_abs_diff_eq!(w, 0.5671432904097838, epsilon = 1e-7);
/// ```
/// Arguments smaller than -1/e (≈ -0.36787944117144233) result in `None`:
/// ```
Expand All @@ -40,14 +38,12 @@ pub fn lambert_w_0(z: f64) -> Option<f64> {
///
/// Basic usage:
/// ```
/// # use approx::assert_abs_diff_eq;
/// use lambert_w::fast::lambert_w_m1;
///
/// use approx::assert_abs_diff_eq;
/// use core::f64::consts::PI;
///
/// let w = lambert_w_m1(-1.0/PI).unwrap();
/// let w = lambert_w_m1(-f64::ln(2.0) / 2.0).unwrap();
///
/// assert_abs_diff_eq!(w, -1.6385284199703634, epsilon = 1e-7);
/// assert_abs_diff_eq!(w, -f64::ln(4.0), epsilon = 1e-9);
/// ```
/// Arguments smaller than -1/e (≈ -0.36787944117144233) or larger than 0 result in `None`:
/// ```
Expand Down
13 changes: 6 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
doc = r##"
```
use lambert_w::accurate::lambert_w_0;
// This macro is used in the documentation examples of this crate.
// It passes the assertion if the two supplied values are the same to within floating point error,
// or within an optional epsilon.
use approx::assert_abs_diff_eq;
# use approx::assert_abs_diff_eq;
let w = lambert_w_0(1.0).unwrap();
Expand All @@ -28,17 +25,19 @@ assert_abs_diff_eq!(w, 0.5671432904097838);
feature = "24bits",
doc = r##"
```
# use approx::assert_abs_diff_eq;
use lambert_w::fast::lambert_w_0;
use approx::assert_abs_diff_eq;
let w = lambert_w_0(1.0).unwrap();
assert_abs_diff_eq!(w, 0.5671432904097838, epsilon = 1e-7);
```
"##
)]
//!
//!
//! The macro is from the [`approx`](https://docs.rs/approx/latest/approx/) crate, and is used in the documentation examples of this crate.
//! It passes the assertion if the two supplied values are the same to within floating point error, or within an optional epsilon.
//!
//! ## Speed-accuracy trade-off
//!
//! The 50-bit accurate versions in the [`accurate`] module are more accurate, but slightly slower, than the 24-bit accurate versions in the [`fast`] module.
Expand Down

0 comments on commit bae0090

Please sign in to comment.