From 7167d55bccee9a84ec7c6cd9c47a7e4a7dcf8f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Wed, 8 May 2024 18:43:52 +0300 Subject: [PATCH] Tweak beta computation in the Gamma distribution --- rand_distr/src/gamma.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 {