@@ -194,7 +194,7 @@ impl<T: Float> Complex<T> {
194194 #[ inline]
195195 pub fn exp ( self ) -> Self {
196196 // formula: e^(a + bi) = e^a (cos(b) + i*sin(b)) = from_polar(e^a, b)
197-
197+
198198 // Treat the corner cases +∞, -∞, and NaN
199199 let mut im = self . im ;
200200 if self . re . is_infinite ( ) {
@@ -211,8 +211,8 @@ impl<T: Float> Complex<T> {
211211 }
212212 }
213213 } else if self . re . is_nan ( ) && self . im == T :: zero ( ) {
214- return self ;
215- }
214+ return self ;
215+ }
216216
217217 Self :: from_polar ( self . re . exp ( ) , im)
218218 }
@@ -1744,40 +1744,47 @@ mod test {
17441744 close
17451745 }
17461746
1747-
17481747 // Version that also works if re or im are +inf, -inf, or nan
17491748 fn close_naninf ( a : Complex64 , b : Complex64 ) -> bool {
17501749 close_naninf_to_tol ( a, b, 1.0e-10 )
17511750 }
17521751
1753-
17541752 fn close_naninf_to_tol ( a : Complex64 , b : Complex64 , tol : f64 ) -> bool {
1755-
17561753 let mut close = true ;
17571754
17581755 // Compare the real parts
17591756 if a. re . is_finite ( ) {
17601757 if b. re . is_finite ( ) {
1761- close = ( a. re == b. re ) || ( a. re - b. re ) . abs ( ) < tol;
1758+ close = ( a. re == b. re ) || ( a. re - b. re ) . abs ( ) < tol;
17621759 } else {
1763- close = false ;
1760+ close = false ;
17641761 }
17651762 } else if ( a. re . is_nan ( ) && !b. re . is_nan ( ) )
1766- || ( a. re . is_infinite ( ) && a. re . is_sign_positive ( ) && !( b. re . is_infinite ( ) && b. re . is_sign_positive ( ) ) )
1767- || ( a. re . is_infinite ( ) && a. re . is_sign_negative ( ) && !( b. re . is_infinite ( ) && b. re . is_sign_negative ( ) ) ) {
1763+ || ( a. re . is_infinite ( )
1764+ && a. re . is_sign_positive ( )
1765+ && !( b. re . is_infinite ( ) && b. re . is_sign_positive ( ) ) )
1766+ || ( a. re . is_infinite ( )
1767+ && a. re . is_sign_negative ( )
1768+ && !( b. re . is_infinite ( ) && b. re . is_sign_negative ( ) ) )
1769+ {
17681770 close = false ;
17691771 }
1770-
1772+
17711773 // Compare the imaginary parts
17721774 if a. im . is_finite ( ) {
17731775 if b. im . is_finite ( ) {
1774- close = ( a. im == b. im ) || ( a. im - b. im ) . abs ( ) < tol;
1776+ close = ( a. im == b. im ) || ( a. im - b. im ) . abs ( ) < tol;
17751777 } else {
1776- close = false ;
1778+ close = false ;
17771779 }
17781780 } else if ( a. im . is_nan ( ) && !b. im . is_nan ( ) )
1779- || ( a. im . is_infinite ( ) && a. im . is_sign_positive ( ) && !( b. im . is_infinite ( ) && b. im . is_sign_positive ( ) ) )
1780- || ( a. im . is_infinite ( ) && a. im . is_sign_negative ( ) && !( b. im . is_infinite ( ) && b. im . is_sign_negative ( ) ) ) {
1781+ || ( a. im . is_infinite ( )
1782+ && a. im . is_sign_positive ( )
1783+ && !( b. im . is_infinite ( ) && b. im . is_sign_positive ( ) ) )
1784+ || ( a. im . is_infinite ( )
1785+ && a. im . is_sign_negative ( )
1786+ && !( b. im . is_infinite ( ) && b. im . is_sign_negative ( ) ) )
1787+ {
17811788 close = false ;
17821789 }
17831790
@@ -1787,7 +1794,6 @@ mod test {
17871794 close
17881795 }
17891796
1790-
17911797 #[ test]
17921798 fn test_exp ( ) {
17931799 assert ! ( close( _1_0i. exp( ) , _1_0i. scale( f64 :: consts:: E ) ) ) ;
@@ -1810,21 +1816,27 @@ mod test {
18101816
18111817 // The test values below were taken from https://en.cppreference.com/w/cpp/numeric/complex/exp
18121818 assert ! ( close_naninf( _1_infi. exp( ) , _nan_nani) ) ;
1813- assert ! ( close_naninf( _neg1_infi. exp( ) , _nan_nani) ) ;
1814- assert ! ( close_naninf( _1_nani. exp( ) , _nan_nani) ) ;
1819+ assert ! ( close_naninf( _neg1_infi. exp( ) , _nan_nani) ) ;
1820+ assert ! ( close_naninf( _1_nani. exp( ) , _nan_nani) ) ;
18151821 assert ! ( close_naninf( _neg1_nani. exp( ) , _nan_nani) ) ;
18161822 assert ! ( close_naninf( _inf_0i. exp( ) , _inf_0i) ) ;
18171823 assert ! ( close_naninf( _neginf_1i. exp( ) , 0.0 * Complex :: cis( 1.0 ) ) ) ;
18181824 assert ! ( close_naninf( _neginf_neg1i. exp( ) , 0.0 * Complex :: cis( -1.0 ) ) ) ;
1819- assert ! ( close_naninf( _inf_1i. exp( ) , f64 :: INFINITY * Complex :: cis( 1.0 ) ) ) ;
1820- assert ! ( close_naninf( _inf_neg1i. exp( ) , f64 :: INFINITY * Complex :: cis( -1.0 ) ) ) ;
1821- assert ! ( close_naninf( _neginf_infi. exp( ) , _0_0i) ) ; // Note: ±0±0i: signs of zeros are unspecified
1822- assert ! ( close_naninf( _inf_infi. exp( ) , _inf_nani) ) ; // Note: ±∞+NaN*i: sign of the real part is unspecified
1823- assert ! ( close_naninf( _neginf_nani. exp( ) , _0_0i) ) ; // Note: ±0±0i: signs of zeros are unspecified
1824- assert ! ( close_naninf( _inf_nani. exp( ) , _inf_nani) ) ; // Note: ±∞+NaN*i: sign of the real part is unspecified
1825+ assert ! ( close_naninf(
1826+ _inf_1i. exp( ) ,
1827+ f64 :: INFINITY * Complex :: cis( 1.0 )
1828+ ) ) ;
1829+ assert ! ( close_naninf(
1830+ _inf_neg1i. exp( ) ,
1831+ f64 :: INFINITY * Complex :: cis( -1.0 )
1832+ ) ) ;
1833+ assert ! ( close_naninf( _neginf_infi. exp( ) , _0_0i) ) ; // Note: ±0±0i: signs of zeros are unspecified
1834+ assert ! ( close_naninf( _inf_infi. exp( ) , _inf_nani) ) ; // Note: ±∞+NaN*i: sign of the real part is unspecified
1835+ assert ! ( close_naninf( _neginf_nani. exp( ) , _0_0i) ) ; // Note: ±0±0i: signs of zeros are unspecified
1836+ assert ! ( close_naninf( _inf_nani. exp( ) , _inf_nani) ) ; // Note: ±∞+NaN*i: sign of the real part is unspecified
18251837 assert ! ( close_naninf( _nan_0i. exp( ) , _nan_0i) ) ;
18261838 assert ! ( close_naninf( _nan_1i. exp( ) , _nan_nani) ) ;
1827- assert ! ( close_naninf( _nan_neg1i. exp( ) , _nan_nani) ) ;
1839+ assert ! ( close_naninf( _nan_neg1i. exp( ) , _nan_nani) ) ;
18281840 assert ! ( close_naninf( _nan_nani. exp( ) , _nan_nani) ) ;
18291841 }
18301842
0 commit comments