Skip to content

Commit f1903ec

Browse files
committed
Fixes nan value for powc of zero
1 parent 23ccbd9 commit f1903ec

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ impl<T: Float> Complex<T> {
373373
// = p^c e^(−d θ) (cos(c θ + d ln(ρ)) + i sin(c θ + d ln(ρ)))
374374
// = from_polar(p^c e^(−d θ), c θ + d ln(ρ))
375375
let (r, theta) = self.to_polar();
376+
377+
if r.is_zero() {
378+
return Self::new(r, r);
379+
}
376380
Self::from_polar(
377381
r.powf(exp.re) * (-exp.im * theta).exp(),
378382
exp.re * theta + exp.im * r.ln(),
@@ -1908,6 +1912,8 @@ pub(crate) mod test {
19081912
Complex::new(1.65826, -0.33502),
19091913
1e-5
19101914
));
1915+
let z = Complex::new(0.0, 0.0);
1916+
assert!(close(z.powc(b), z));
19111917
}
19121918

19131919
#[test]

0 commit comments

Comments
 (0)