Skip to content

Commit

Permalink
style: use literals with comments instead of const
Browse files Browse the repository at this point in the history
  • Loading branch information
YeungOnion committed May 24, 2024
1 parent e46d123 commit 6699215
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/distribution/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ impl ContinuousCDF<f64, f64> for Gamma {
}

fn inverse_cdf(&self, p: f64) -> f64 {
const MAX_ITERS: (u16, u16) = (8, 4);
if !(0.0..=1.0).contains(&p) {
panic!("default inverse_cdf implementation should be provided probability on [0,1]")
}
Expand All @@ -167,7 +166,7 @@ impl ContinuousCDF<f64, f64> for Gamma {
}
let mut x_0 = (high + low) / 2.0;

for _ in 0..MAX_ITERS.0 {
for _ in 0..8 {
if self.cdf(x_0) >= p {
high = x_0;
} else {
Expand All @@ -178,8 +177,8 @@ impl ContinuousCDF<f64, f64> for Gamma {
}
}

// NR method, guarantee at least one step
for _ in 0..MAX_ITERS.1 {
// Newton Raphson, for at least one step
for _ in 0..4 {
let x_next = x_0 - (self.cdf(x_0) - p) / self.pdf(x_0);
if prec::convergence(&mut x_0, x_next) {
break;
Expand Down

0 comments on commit 6699215

Please sign in to comment.