Skip to content

Commit 07a1836

Browse files
committed
Made complex exp() more readable.
1 parent a83b916 commit 07a1836

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,26 +195,26 @@ impl<T: Float> Complex<T> {
195195
pub fn exp(self) -> Self {
196196
// formula: e^(a + bi) = e^a (cos(b) + i*sin(b)) = from_polar(e^a, b)
197197

198+
let Complex { re, mut im } = self;
198199
// Treat the corner cases +∞, -∞, and NaN
199-
let mut im = self.im;
200-
if self.re.is_infinite() {
201-
if self.re < T::zero() {
202-
if !self.im.is_finite() {
203-
im = T::one();
200+
if re.is_infinite() {
201+
if re < T::zero() {
202+
if !im.is_finite() {
203+
return Self::new(T::zero(), T::zero());
204204
}
205205
} else {
206-
if self.im == T::zero() || !self.im.is_finite() {
207-
if self.im.is_infinite() {
206+
if im == T::zero() || !im.is_finite() {
207+
if im.is_infinite() {
208208
im = T::nan();
209209
}
210-
return Self::new(self.re, im);
210+
return Self::new(re, im);
211211
}
212212
}
213-
} else if self.re.is_nan() && self.im == T::zero() {
213+
} else if re.is_nan() && im == T::zero() {
214214
return self;
215215
}
216216

217-
Self::from_polar(self.re.exp(), im)
217+
Self::from_polar(re.exp(), im)
218218
}
219219

220220
/// Computes the principal value of natural logarithm of `self`.

0 commit comments

Comments
 (0)