From ceb96227087b7dcd7f0fee42635aab7873f1e962 Mon Sep 17 00:00:00 2001 From: Goose Date: Wed, 24 Sep 2025 16:36:52 +1000 Subject: [PATCH] fix(clippy): use constants provided by core --- src/distribution/cauchy.rs | 2 +- src/distribution/exponential.rs | 4 ++-- src/distribution/hypergeometric.rs | 6 +++--- src/distribution/laplace.rs | 2 +- src/distribution/uniform.rs | 10 +++++----- src/distribution/weibull.rs | 4 ++-- src/function/beta.rs | 14 +++++++------- src/function/gamma.rs | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/distribution/cauchy.rs b/src/distribution/cauchy.rs index e6d00eb8..cf3c7f3b 100644 --- a/src/distribution/cauchy.rs +++ b/src/distribution/cauchy.rs @@ -355,7 +355,7 @@ mod tests { test_exact(0.0, 0.1, 0.001272730452554141029739, pdf(5.0)); test_absolute(0.0, 1.0, 0.01224268793014579505914, 1e-17, pdf(-5.0)); test_exact(0.0, 1.0, 0.1591549430918953357689, pdf(-1.0)); - test_exact(0.0, 1.0, 0.3183098861837906715378, pdf(0.0)); + test_exact(0.0, 1.0, f64::consts::FRAC_1_PI, pdf(0.0)); test_exact(0.0, 1.0, 0.1591549430918953357689, pdf(1.0)); test_absolute(0.0, 1.0, 0.01224268793014579505914, 1e-17, pdf(5.0)); test_exact(0.0, 10.0, 0.02546479089470325372302, pdf(-5.0)); diff --git a/src/distribution/exponential.rs b/src/distribution/exponential.rs index 54d3e263..b7a0436e 100644 --- a/src/distribution/exponential.rs +++ b/src/distribution/exponential.rs @@ -412,9 +412,9 @@ mod tests { #[test] fn test_ln_pdf() { let ln_pdf = |arg: f64| move |x: Exp| x.ln_pdf(arg); - test_absolute(0.1, -2.302585092994045684018, 1e-15, ln_pdf(0.0)); + test_absolute(0.1, -f64::consts::LN_10, 1e-15, ln_pdf(0.0)); test_exact(1.0, 0.0, ln_pdf(0.0)); - test_exact(10.0, 2.302585092994045684018, ln_pdf(0.0)); + test_exact(10.0, f64::consts::LN_10, ln_pdf(0.0)); test_is_nan(f64::INFINITY, ln_pdf(0.0)); test_absolute(0.1, -2.312585092994045684018, 1e-15, ln_pdf(0.1)); test_exact(1.0, -0.1, ln_pdf(0.1)); diff --git a/src/distribution/hypergeometric.rs b/src/distribution/hypergeometric.rs index c09677fe..3ca4d48f 100644 --- a/src/distribution/hypergeometric.rs +++ b/src/distribution/hypergeometric.rs @@ -540,11 +540,11 @@ mod tests { let ln_pmf = |arg: u64| move |x: Hypergeometric| x.ln_pmf(arg); test_exact(0, 0, 0, 0.0, ln_pmf(0)); test_exact(1, 1, 1, 0.0, ln_pmf(1)); - test_exact(2, 1, 1, -0.6931471805599453094172, ln_pmf(0)); - test_exact(2, 1, 1, -0.6931471805599453094172, ln_pmf(1)); + test_exact(2, 1, 1, -f64::consts::LN_2, ln_pmf(0)); + test_exact(2, 1, 1, -f64::consts::LN_2, ln_pmf(1)); test_exact(2, 2, 2, 0.0, ln_pmf(2)); test_absolute(10, 1, 1, -0.1053605156578263012275, 1e-14, ln_pmf(0)); - test_absolute(10, 1, 1, -2.302585092994045684018, 1e-14, ln_pmf(1)); + test_absolute(10, 1, 1, -f64::consts::LN_10, 1e-14, ln_pmf(1)); test_absolute(10, 5, 3, -0.875468737353899935621, 1e-14, ln_pmf(1)); test_absolute(10, 5, 3, -2.484906649788000310234, 1e-14, ln_pmf(3)); } diff --git a/src/distribution/laplace.rs b/src/distribution/laplace.rs index fd65f262..85bb45e6 100644 --- a/src/distribution/laplace.rs +++ b/src/distribution/laplace.rs @@ -550,7 +550,7 @@ mod tests { test_rel_close(loc, scale, expected, reltol, inverse_cdf(0.001)); // Wolfram Alpha: Inverse CDF[LaplaceDistribution[0, 1], 95/100] - let expected = 2.3025850929940456840179914546843642f64; + let expected = f64::consts::LN_10; test_rel_close(loc, scale, expected, reltol, inverse_cdf(0.95)); } diff --git a/src/distribution/uniform.rs b/src/distribution/uniform.rs index 91218882..bdb87444 100644 --- a/src/distribution/uniform.rs +++ b/src/distribution/uniform.rs @@ -388,8 +388,8 @@ mod tests { #[test] fn test_entropy() { let entropy = |x: Uniform| x.entropy().unwrap(); - test_exact(-0.0, 2.0, 0.6931471805599453094172, entropy); - test_exact(0.0, 2.0, 0.6931471805599453094172, entropy); + test_exact(-0.0, 2.0, f64::consts::LN_2, entropy); + test_exact(0.0, 2.0, f64::consts::LN_2, entropy); test_absolute(0.1, 4.0, 1.360976553135600743431, 1e-15, entropy); test_exact(1.0, 10.0, 2.19722457733621938279, entropy); test_exact(10.0, 11.0, 0.0, entropy); @@ -448,14 +448,14 @@ mod tests { fn test_ln_pdf() { let ln_pdf = |arg: f64| move |x: Uniform| x.ln_pdf(arg); test_exact(0.0, 0.1, f64::NEG_INFINITY, ln_pdf(-5.0)); - test_absolute(0.0, 0.1, 2.302585092994045684018, 1e-15, ln_pdf(0.05)); + test_absolute(0.0, 0.1, f64::consts::LN_10, 1e-15, ln_pdf(0.05)); test_exact(0.0, 0.1, f64::NEG_INFINITY, ln_pdf(5.0)); test_exact(0.0, 1.0, f64::NEG_INFINITY, ln_pdf(-5.0)); test_exact(0.0, 1.0, 0.0, ln_pdf(0.5)); test_exact(0.0, 0.1, f64::NEG_INFINITY, ln_pdf(5.0)); test_exact(0.0, 10.0, f64::NEG_INFINITY, ln_pdf(-5.0)); - test_exact(0.0, 10.0, -2.302585092994045684018, ln_pdf(1.0)); - test_exact(0.0, 10.0, -2.302585092994045684018, ln_pdf(5.0)); + test_exact(0.0, 10.0, -f64::consts::LN_10, ln_pdf(1.0)); + test_exact(0.0, 10.0, -f64::consts::LN_10, ln_pdf(5.0)); test_exact(0.0, 10.0, f64::NEG_INFINITY, ln_pdf(11.0)); test_exact(-5.0, 100.0, f64::NEG_INFINITY, ln_pdf(-10.0)); test_exact(-5.0, 100.0, -4.653960350157523371101, ln_pdf(-5.0)); diff --git a/src/distribution/weibull.rs b/src/distribution/weibull.rs index aef0b271..d3cc8748 100644 --- a/src/distribution/weibull.rs +++ b/src/distribution/weibull.rs @@ -446,7 +446,7 @@ mod tests { fn test_median() { let median = |x: Weibull| x.median(); test_exact(1.0, 0.1, 0.069314718055994530941723212145817656807550013436026, median); - test_exact(1.0, 1.0, 0.69314718055994530941723212145817656807550013436026, median); + test_exact(1.0, 1.0, f64::consts::LN_2, median); test_exact(10.0, 10.0, 9.6401223546778973665856033763604752124634905617583, median); test_exact(10.0, 1.0, 0.96401223546778973665856033763604752124634905617583, median); } @@ -488,7 +488,7 @@ mod tests { #[test] fn test_ln_pdf() { let ln_pdf = |arg: f64| move |x: Weibull| x.ln_pdf(arg); - test_absolute(1.0, 0.1, 2.3025850929940456840179914546843642076011014886288, 1e-15, ln_pdf(0.0)); + test_absolute(1.0, 0.1, f64::consts::LN_10, 1e-15, ln_pdf(0.0)); test_absolute(1.0, 0.1, -7.6974149070059543159820085453156357923988985113712, 1e-15, ln_pdf(1.0)); test_exact(1.0, 0.1, -97.697414907005954315982008545315635792398898511371, ln_pdf(10.0)); test_exact(1.0, 1.0, 0.0, ln_pdf(0.0)); diff --git a/src/function/beta.rs b/src/function/beta.rs index 4e3e63ab..6f157071 100644 --- a/src/function/beta.rs +++ b/src/function/beta.rs @@ -450,9 +450,9 @@ mod tests { #[test] fn test_ln_beta() { beta_assert_relative_eq(ln_beta(0.5, 0.5), 1.144729885849400174144); - beta_assert_relative_eq(ln_beta(1.0, 0.5), 0.6931471805599453094172); + beta_assert_relative_eq(ln_beta(1.0, 0.5), f64::consts::LN_2); beta_assert_relative_eq(ln_beta(2.5, 0.5), 0.163900632837673937284); - beta_assert_relative_eq(ln_beta(0.5, 1.0), 0.6931471805599453094172); + beta_assert_relative_eq(ln_beta(0.5, 1.0), f64::consts::LN_2); beta_assert_relative_eq(ln_beta(1.0, 1.0), 0.0); beta_assert_relative_eq(ln_beta(2.5, 1.0), -0.9162907318741550651835); beta_assert_relative_eq(ln_beta(0.5, 2.5), 0.163900632837673937284); @@ -506,7 +506,7 @@ mod tests { #[test] fn test_beta() { - beta_assert_relative_eq(beta(0.5, 0.5), 3.141592653589793238463); + beta_assert_relative_eq(beta(0.5, 0.5), f64::consts::PI); beta_assert_relative_eq(beta(1.0, 0.5), 2.0); beta_assert_relative_eq(beta(2.5, 0.5), 1.17809724509617246442); beta_assert_relative_eq(beta(0.5, 1.0), 2.0); @@ -519,13 +519,13 @@ mod tests { #[test] fn test_beta_inc() { - beta_assert_relative_eq(beta_inc(0.5, 0.5, 0.5), 1.570796326794896619231); - beta_assert_relative_eq(beta_inc(0.5, 0.5, 1.0), 3.141592653589793238463); + beta_assert_relative_eq(beta_inc(0.5, 0.5, 0.5), f64::consts::FRAC_PI_2); + beta_assert_relative_eq(beta_inc(0.5, 0.5, 1.0), f64::consts::PI); beta_assert_relative_eq(beta_inc(1.0, 0.5, 0.5), 0.5857864376269049511983); beta_assert_relative_eq(beta_inc(1.0, 0.5, 1.0), 2.0); beta_assert_relative_eq(beta_inc(2.5, 0.5, 0.5), 0.0890486225480862322117); beta_assert_relative_eq(beta_inc(2.5, 0.5, 1.0), 1.17809724509617246442); - beta_assert_relative_eq(beta_inc(0.5, 1.0, 0.5), 1.414213562373095048802); + beta_assert_relative_eq(beta_inc(0.5, 1.0, 0.5), f64::consts::SQRT_2); beta_assert_relative_eq(beta_inc(0.5, 1.0, 1.0), 2.0); beta_assert_relative_eq(beta_inc(1.0, 1.0, 0.5), 0.5); beta_assert_relative_eq(beta_inc(1.0, 1.0, 1.0), 1.0); @@ -591,7 +591,7 @@ mod tests { assert_eq!(beta_reg(1.0, 0.5, 1.0), 1.0); beta_assert_abs_diff_eq(beta_reg(2.5, 0.5, 0.5), 0.07558681842161243795); assert_eq!(beta_reg(2.5, 0.5, 1.0), 1.0); - beta_assert_abs_diff_eq(beta_reg(0.5, 1.0, 0.5), 0.7071067811865475244); + beta_assert_abs_diff_eq(beta_reg(0.5, 1.0, 0.5), f64::consts::FRAC_1_SQRT_2); assert_eq!(beta_reg(0.5, 1.0, 1.0), 1.0); beta_assert_abs_diff_eq(beta_reg(1.0, 1.0, 0.5), 0.5); assert_eq!(beta_reg(1.0, 1.0, 1.0), 1.0); diff --git a/src/function/gamma.rs b/src/function/gamma.rs index bdc8ffba..1f4b79b9 100644 --- a/src/function/gamma.rs +++ b/src/function/gamma.rs @@ -624,7 +624,7 @@ mod tests { ); prec::assert_abs_diff_eq!( super::ln_gamma(3.0), - 0.693147180559945309417232121458176568075500134360255254120680, + f64::consts::LN_2, epsilon = 1e-14 ); prec::assert_abs_diff_eq!(