Skip to content

Commit 59f985d

Browse files
committed
Handle poles
1 parent 931e421 commit 59f985d

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/special/lanczos.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn ln_gamma_approx(z: f64) -> f64 {
2626
if z <= 0.0 && z.fract() == 0.0 {
2727
return f64::INFINITY;
2828
}
29-
29+
3030
if z < 0.5 {
3131
return PI.ln() - (PI * z).sin().abs().ln() - ln_gamma_approx(1.0 - z);
3232
}
@@ -42,18 +42,19 @@ pub fn ln_gamma_approx(z: f64) -> f64 {
4242
}
4343

4444
pub fn gamma_approx(z: f64) -> f64 {
45-
if z > 1f64 {
46-
let z_int = z as usize;
47-
if z - (z_int as f64) == 0f64 {
48-
return factorial(z_int - 1) as f64;
45+
if z <= 0.0 && z.fract() == 0.0 {
46+
if z == 0.0 {
47+
return f64::INFINITY;
48+
} else {
49+
return f64::NAN;
4950
}
5051
}
5152

5253
if z < 0.5 {
53-
PI / ((PI * z).sin() * gamma_approx(1f64 - z))
54-
} else {
55-
ln_gamma_approx(z).exp()
54+
return PI / ((PI * z).sin() * gamma_approx(1f64 - z));
5655
}
56+
57+
ln_gamma_approx(z).exp()
5758
}
5859

5960
/// Lanczos Approximation Coefficient

0 commit comments

Comments
 (0)