File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed
Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -193,9 +193,28 @@ impl<T: Float> Complex<T> {
193193 /// Computes `e^(self)`, where `e` is the base of the natural logarithm.
194194 #[ inline]
195195 pub fn exp ( self ) -> Self {
196- // formula: e^(a + bi) = e^a (cos(b) + i*sin(b))
197- // = from_polar(e^a, b)
198- Self :: from_polar ( self . re . exp ( ) , self . im )
196+ // formula: e^(a + bi) = e^a (cos(b) + i*sin(b)) = from_polar(e^a, b)
197+
198+ // 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 ( ) ;
204+ }
205+ } else {
206+ if self . im == T :: zero ( ) || !self . im . is_finite ( ) {
207+ if self . im . is_infinite ( ) {
208+ im = T :: nan ( ) ;
209+ }
210+ return Self :: new ( self . re , im) ;
211+ }
212+ }
213+ } else if self . re . is_nan ( ) && self . im == T :: zero ( ) {
214+ return self ;
215+ }
216+
217+ Self :: from_polar ( self . re . exp ( ) , im)
199218 }
200219
201220 /// Computes the principal value of natural logarithm of `self`.
You can’t perform that action at this time.
0 commit comments