diff --git a/rand_distr/src/gamma.rs b/rand_distr/src/gamma.rs index 11385beac1..fbafd26824 100644 --- a/rand_distr/src/gamma.rs +++ b/rand_distr/src/gamma.rs @@ -620,8 +620,12 @@ where if a > F::one() { // Algorithm BB let alpha = a + b; - let beta = - ((alpha - F::from(2.).unwrap()) / (F::from(2.).unwrap() * a * b - alpha)).sqrt(); + + let two = F::from(2.).unwrap(); + let beta_numer = alpha - two; + let beta_denom = two * a * b - alpha; + let beta = (beta_numer / beta_denom).sqrt(); + let gamma = a + F::one() / beta; Ok(Beta {