Skip to content

Commit e956a48

Browse files
committed
Fixed mistake in the domain getting passed into the tangent function
1 parent a391f2c commit e956a48

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/distributions/cauchy.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ impl Cauchy {
4949

5050
impl Distribution<f64> for Cauchy {
5151
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64 {
52-
let mut x = rng.gen::<f64>();
53-
// guard against the extremely unlikely event we get 0 or 1 from the generator
54-
while x <= 0.0 || x >= 1.0 {
52+
// sample from [0, 1)
53+
let mut x: f64 = rng.gen::<f64>();
54+
// guard against the extremely unlikely case we get the invalid 0.5
55+
while x == 0.5 {
5556
x = rng.gen::<f64>();
5657
}
5758
// get standard cauchy random number
58-
let comp_dev = (2.0 * PI * x).tan();
59+
let comp_dev = (PI * x).tan();
5960
// shift and scale according to parameters
6061
let result = self.median + self.scale * comp_dev;
6162
result

0 commit comments

Comments
 (0)