Skip to content

Commit

Permalink
Fixes nan value for powc of zero
Browse files Browse the repository at this point in the history
  • Loading branch information
domna committed May 22, 2023
1 parent 23ccbd9 commit f1903ec
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ impl<T: Float> Complex<T> {
// = p^c e^(−d θ) (cos(c θ + d ln(ρ)) + i sin(c θ + d ln(ρ)))
// = from_polar(p^c e^(−d θ), c θ + d ln(ρ))
let (r, theta) = self.to_polar();

if r.is_zero() {
return Self::new(r, r);
}
Self::from_polar(
r.powf(exp.re) * (-exp.im * theta).exp(),
exp.re * theta + exp.im * r.ln(),
Expand Down Expand Up @@ -1908,6 +1912,8 @@ pub(crate) mod test {
Complex::new(1.65826, -0.33502),
1e-5
));
let z = Complex::new(0.0, 0.0);
assert!(close(z.powc(b), z));
}

#[test]
Expand Down

0 comments on commit f1903ec

Please sign in to comment.