Skip to content

Commit

Permalink
Remove estrin feature and set version number to 1.0.0 (#27)
Browse files Browse the repository at this point in the history
* Remove `estrin` feature.
Bump version to 1.0.0
  • Loading branch information
JSorngard authored Oct 9, 2024
1 parent 7cf34f2 commit 76fe231
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 230 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: test
run: cargo test --no-default-features -F libm && cargo test --no-default-features -F libm,24bits && cargo test --no-default-features -F libm,50bits && cargo test --no-default-features -F libm,24bits,50bits && cargo test --no-default-features -F libm,24bits,estrin && cargo test --no-default-features -F libm,50bits,estrin && cargo test --no-default-features -F libm,24bits,50bits,estrin && cargo test --no-default-features -F std && cargo test --no-default-features -F std,24bits && cargo test --no-default-features -F std,50bits && cargo test --no-default-features -F std,24bits,50bits && cargo test --no-default-features -F std,24bits,estrin && cargo test --no-default-features -F std,50bits,estrin && cargo test --no-default-features -F std,24bits,50bits,estrin && cargo test --no-default-features -F std,libm && cargo test --no-default-features -F std,libm,24bits && cargo test --no-default-features -F std,libm,50bits && cargo test --no-default-features -F std,libm,24bits,50bits && cargo test --no-default-features -F std,libm,24bits,estrin && cargo test --no-default-features -F std,libm,50bits,estrin && cargo test --no-default-features -F std,libm,24bits,50bits,estrin
run: cargo test --no-default-features -F libm && cargo test --no-default-features -F libm,24bits && cargo test --no-default-features -F libm,50bits && cargo test --no-default-features -F libm,24bits,50bits && cargo test --no-default-features -F std && cargo test --no-default-features -F std,24bits && cargo test --no-default-features -F std,50bits && cargo test --no-default-features -F std,24bits,50bits && cargo test --no-default-features -F std,libm && cargo test --no-default-features -F std,libm,24bits && cargo test --no-default-features -F std,libm,50bits && cargo test --no-default-features -F std,libm,24bits,50bits
#run: cargo install cargo-all-features && cargo test-all-features

doc:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

This file contains the changes to the crate since version 0.1.1.

## Unreleased

- Remove `estrin` feature.
If it was activated anywhere in the dependency tree the crate became less
accurate for all users (as the compiler assumes that features are additive),
without them being able to do anything about it.

## 0.5.9

- Add the `LambertW` trait that lets the user call the Lambert W functions
Expand Down
13 changes: 1 addition & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lambert_w"
version = "0.5.9"
version = "1.0.0"
edition = "2021"
authors = ["Johanna Sörngård <[email protected]>"]
categories = ["mathematics", "no-std::no-alloc"]
Expand All @@ -12,7 +12,6 @@ repository = "https://github.com/JSorngard/lambert_w"
documentation = "https://docs.rs/lambert_w"

[dependencies]
fast_polynomial = { version = "0.3.0", default-features = false, optional = true }
libm = { version = "0.2.8", optional = true }

[dev-dependencies]
Expand All @@ -26,17 +25,12 @@ default = ["24bits", "50bits", "libm"]
50bits = []
# Enables the function versions with 24 bits of accuracy on 64-bit floats, as well as the implementation on 32-bit floats.
24bits = []
# Uses [Estrin's scheme](https://en.wikipedia.org/wiki/Estrin's_scheme) to evaluate the polynomials in the rational functions.
# While this results in more assembly instructions, they are mostly independent of each other,
# and this increases instruction level parallelism on modern hardware for a total performance gain.
# May result in slight numerical instability, which can be reduced if the target CPU has fused multiply-add instructions.
estrin = ["dep:fast_polynomial"]
# If the `std` feature is disabled, this feature uses the [`libm`](https://crates.io/crates/libm) crate
# to compute square roots and logarithms instead of the standard library.
libm = ["dep:libm", "fast_polynomial?/libm"]
libm = ["dep:libm"]
# Use the standard library to compute square roots and logarithms for a potential performance gain.
# When this feature is disabled the crate is `no_std` compatible.
std = ["fast_polynomial?/std"]
std = []

[package.metadata.docs.rs]
# Document all features.
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ but this reduction has not been quantified by the author of this crate.
The crate is `no_std` compatible, but can optionally depend on the standard
library through features for a potential performance gain.

The API of the crate is stable and the only
reason it's not at version `1.0.0` is because its
dependencies are not.

## Examples

Compute the value of the
Expand Down
113 changes: 0 additions & 113 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
//!
//! The crate is `no_std` compatible, but can optionally depend on the standard library through features for a potential performance gain.
//!
//! The API of the crate is stable and the only reason it's not at version `1.0.0` is because its dependencies are not.
//!
//! ## Examples
//!
//! Compute the value of the [omega constant](https://en.wikipedia.org/wiki/Omega_constant) with the principal branch of the Lambert W function:
Expand Down Expand Up @@ -117,11 +115,6 @@ assert_abs_diff_eq!(z.lambert_w0(), f64::ln(2.0));
//!
//! You can disable one of the above features to potentially save a little bit of binary size.
//!
//! `estrin`: uses [Estrin's scheme](https://en.wikipedia.org/wiki/Estrin's_scheme) to evaluate the polynomials in the rational functions.
//! While this results in more assembly instructions, they are mostly independent of each other,
//! and this increases instruction level parallelism on modern hardware for a total performance gain.
//! May result in slight numerical instability, which can be reduced if the target CPU has fused multiply-add instructions.
//!
//! One of the below features must be enabled:
//!
//! `std`: use the standard library to compute square roots and logarithms
Expand Down Expand Up @@ -430,10 +423,6 @@ impl LambertW for f64 {

#[cfg(all(test, any(feature = "24bits", feature = "50bits")))]
mod test {
// A lot of these tests are less stringent when the `estrin` feature flag is activated.
// This is because Estrin's scheme is less numerically stable,
// and CI may also not have fused multiply-add instructions to reduce the instabillity.

use super::LambertW;
#[cfg(feature = "50bits")]
use super::{lambert_w0, lambert_wm1};
Expand All @@ -454,45 +443,17 @@ mod test {
lambert_w0(6.321_205_588_285_577e-1),
4.167_039_988_177_658e-1
);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0(9.632120558828557), 1.721757710976171);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_w0(9.632120558828557),
1.721757710976171,
epsilon = 1e-14
);
assert_abs_diff_eq!(lambert_w0(9.963_212_055_882_856e1), 3.382785211058958);
assert_abs_diff_eq!(lambert_w0(9.996_321_205_588_285e2), 5.249293782013269);
assert_abs_diff_eq!(
lambert_w0(9.999_632_120_558_828e3),
7.231813718542178,
epsilon = 1e-14
);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0(9.999_963_212_055_883e4), 9.284_568_107_521_96);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_w0(9.999963212055883e+04),
9.284568107521959,
epsilon = 1e-14
);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0(9.999_996_321_205_589e5), 1.138_335_774_796_812e1);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_w0(9.999996321205589e+05),
1.138335774796812e+01,
epsilon = 1e-14
);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0(9.999_999_632_120_559e6), 1.351_434_397_605_273e1);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_w0(9.999999632120559e+06),
1.351434397605273e+01,
epsilon = 1e-14
);
assert_abs_diff_eq!(
lambert_w0(9.999_999_963_212_056e7),
1.566_899_671_199_287e1,
Expand All @@ -508,34 +469,20 @@ mod test {
2.002_868_541_326_992e1,
epsilon = 1e-14
);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(
lambert_w0(9.999_999_999_963_213e10),
2.222_712_273_495_755e1
);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_w0(9.999999999963213e+10),
2.222712273495755e+01,
epsilon = 1e-14
);
assert_abs_diff_eq!(
lambert_w0(9.999_999_999_996_321e11),
2.443_500_440_493_456e1,
epsilon = 1e-14
);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(
lambert_w0(9.999_999_999_999_633e12),
2.665_078_750_870_219e1,
epsilon = 1e-14
);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_w0(9.999999999999633e+12),
2.665078750870219e+01,
epsilon = 1e-13
);
assert_abs_diff_eq!(
lambert_w0(9.999_999_999_999_963e13),
2.887_327_487_929_93e1,
Expand All @@ -547,32 +494,11 @@ mod test {
epsilon = 1e-14
);
assert_abs_diff_eq!(lambert_w0(1e16), 3.333_476_076_844_818e1, epsilon = 1e-14);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0(1e17), 3.557_237_716_651_325e1);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_w0(1.000000000000000e+17),
3.557237716651325e+01,
epsilon = 1e-14
);
assert_abs_diff_eq!(lambert_w0(1e18), 3.781_385_607_558_877e1, epsilon = 1e-14);
assert_abs_diff_eq!(lambert_w0(1e19), 4.005_876_916_198_432e1, epsilon = 1e-14);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0(1e20), 4.230_675_509_173_839e1);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_w0(1.000000000000000e+20),
4.230675509173839e+01,
epsilon = 1e-14
);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0(1e40), 8.763_027_715_194_72e1);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_w0(1.000000000000000e+40),
8.763027715194720e+01,
epsilon = 1e-13
);
assert_abs_diff_eq!(lambert_w0(1e80), 1.790_193_137_415_062e2, epsilon = 1e-13);
assert_abs_diff_eq!(lambert_w0(1e120), 2.707_091_661_024_979e2, epsilon = 1e-13);
assert_abs_diff_eq!(lambert_w0(1e160), 3.625_205_337_614_976e2);
Expand Down Expand Up @@ -701,32 +627,17 @@ mod test {
assert_abs_diff_eq!(lambert_w0f(9.632_12), 1.721_757_8, epsilon = 1e-6);
assert_abs_diff_eq!(lambert_w0f(9.963_212e1), 3.382_785_3, epsilon = 1e-6);
assert_abs_diff_eq!(lambert_w0f(9.996_321_4e2), 5.249_294, epsilon = 1e-6);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0f(9.999_632e3), 7.231_814, epsilon = 1e-7);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(lambert_w0f(9.999_632e3), 7.231_814, epsilon = 1e-6);
assert_abs_diff_eq!(lambert_w0f(9.999_963e4), 9.284_568, epsilon = 1e-6);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0f(9.999_996e5), 1.138_335_8e1, epsilon = 1e-8);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(lambert_w0f(9.999_996e5), 1.138_335_8e1, epsilon = 1e-6);
assert_abs_diff_eq!(lambert_w0f(1e7), 1.351_434_4e1, epsilon = 1e-6);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0f(1e8), 1.566_899_7e1, epsilon = 1e-6);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(lambert_w0f(1e8), 1.566_899_7e1, epsilon = 1e-5);
assert_abs_diff_eq!(lambert_w0f(1e9), 1.784_172_6e1, epsilon = 1e-6);
assert_abs_diff_eq!(lambert_w0f(1e10), 2.002_868_5e1, epsilon = 1e-5);
assert_abs_diff_eq!(lambert_w0f(1e11), 2.222_712_3e1, epsilon = 1e-5);
assert_abs_diff_eq!(lambert_w0f(1e12), 2.443_500_5e1, epsilon = 1e-5);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0f(1e13), 2.665_078_7e1, epsilon = 1e-6);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(lambert_w0f(1e13), 2.665_078_7e1, epsilon = 1e-5);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_w0f(1e14), 2.887_327_6e1, epsilon = 1e-6);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(lambert_w0f(1e14), 2.887_327_6e1, epsilon = 1e-5);
assert_abs_diff_eq!(lambert_w0f(1e15), 3.110_152e1, epsilon = 1e-5);
assert_abs_diff_eq!(lambert_w0f(1e16), 3.333_476_3e1, epsilon = 1e-5);
assert_abs_diff_eq!(lambert_w0f(1e17), 3.557_237_6e1, epsilon = 1e-5);
Expand All @@ -751,14 +662,7 @@ mod test {
epsilon = 1e-14
);
assert_abs_diff_eq!(lambert_wm1(-1e-1), -3.577152063957297);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_wm1(-3e-2), -5.144482721515681);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_wm1(-3.000000000000000e-02),
-5.144482721515681,
epsilon = 1e-14
);
assert_abs_diff_eq!(lambert_wm1(-1e-2), -6.472775124394005, epsilon = 1e-14);
assert_abs_diff_eq!(lambert_wm1(-3e-3), -7.872521380098709, epsilon = 1e-14);
assert_abs_diff_eq!(lambert_wm1(-1e-3), -9.118006470402742, epsilon = 1e-14);
Expand Down Expand Up @@ -787,17 +691,10 @@ mod test {
-1.778_749_628_219_512e2,
epsilon = 1e-13
);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(
lambert_wm1(-1.000000000000008e-145),
-3.397_029_099_254_29e2
);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_wm1(-1.000000000000008e-145),
-3.397029099254290e+02,
epsilon = 1e-12
);
assert!(lambert_wm1(f64::EPSILON).is_nan());
}

Expand Down Expand Up @@ -858,14 +755,7 @@ mod test {
fn test_lambert_wm1f() {
assert!(lambert_wm1f(-1.0 / core::f32::consts::E - f32::EPSILON).is_nan());
assert_abs_diff_eq!(lambert_wm1f(-3.578_794_3e-1), -1.253_493_8, epsilon = 1e-6);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_wm1f(-2.678_794_3e-1), -2.020_625, epsilon = 1e-7);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(
lambert_wm1f(-2.678_794_411_714_424e-1),
-2.020625228775403,
epsilon = 1e-6
);
assert_abs_diff_eq!(lambert_wm1f(-1e-1), -3.577_152, epsilon = 1e-6);
assert_abs_diff_eq!(lambert_wm1f(-3e-2), -5.144_482_6, epsilon = 1e-9);
assert_abs_diff_eq!(lambert_wm1f(-1e-2), -6.472_775, epsilon = 1e-6);
Expand All @@ -875,10 +765,7 @@ mod test {
assert_abs_diff_eq!(lambert_wm1f(-1e-4), -1.166_711_4e1, epsilon = 1e-6);
assert_abs_diff_eq!(lambert_wm1f(-3e-5), -1.297_753_2e1, epsilon = 1e-6);
assert_abs_diff_eq!(lambert_wm1f(-1e-5), -1.416_360_1e1, epsilon = 1e-6);
#[cfg(not(feature = "estrin"))]
assert_abs_diff_eq!(lambert_wm1f(-1e-20), -49.962_986);
#[cfg(feature = "estrin")]
assert_abs_diff_eq!(lambert_wm1f(-1e-20), -49.962_986, epsilon = 1e-5);
assert!(lambert_wm1f(f32::EPSILON).is_nan());
}

Expand Down
Loading

0 comments on commit 76fe231

Please sign in to comment.