@@ -361,26 +361,8 @@ impl<T: Float> Complex<T> {
361
361
/// Raises `self` to a complex power.
362
362
#[ inline]
363
363
pub fn powc ( self , exp : Self ) -> Self {
364
- // formula: x^y = (a + i b)^(c + i d)
365
- // = (ρ e^(i θ))^c (ρ e^(i θ))^(i d)
366
- // where ρ=|x| and θ=arg(x)
367
- // = ρ^c e^(−d θ) e^(i c θ) ρ^(i d)
368
- // = p^c e^(−d θ) (cos(c θ)
369
- // + i sin(c θ)) (cos(d ln(ρ)) + i sin(d ln(ρ)))
370
- // = p^c e^(−d θ) (
371
- // cos(c θ) cos(d ln(ρ)) − sin(c θ) sin(d ln(ρ))
372
- // + i(cos(c θ) sin(d ln(ρ)) + sin(c θ) cos(d ln(ρ))))
373
- // = p^c e^(−d θ) (cos(c θ + d ln(ρ)) + i sin(c θ + d ln(ρ)))
374
- // = from_polar(p^c e^(−d θ), c θ + d ln(ρ))
375
- let ( r, theta) = self . to_polar ( ) ;
376
-
377
- if r. is_zero ( ) {
378
- return Self :: new ( r, r) ;
379
- }
380
- Self :: from_polar (
381
- r. powf ( exp. re ) * ( -exp. im * theta) . exp ( ) ,
382
- exp. re * theta + exp. im * r. ln ( ) ,
383
- )
364
+ // formula: x^y = exp(y * ln(x))
365
+ ( exp * self . ln ( ) ) . exp ( )
384
366
}
385
367
386
368
/// Raises a floating point number to the complex power `self`.
@@ -1719,6 +1701,9 @@ pub(crate) mod test {
1719
1701
1720
1702
#[ cfg( any( feature = "std" , feature = "libm" ) ) ]
1721
1703
pub ( crate ) mod float {
1704
+
1705
+ use core:: f64:: INFINITY ;
1706
+
1722
1707
use super :: * ;
1723
1708
use num_traits:: { Float , Pow } ;
1724
1709
@@ -1914,6 +1899,11 @@ pub(crate) mod test {
1914
1899
) ) ;
1915
1900
let z = Complex :: new ( 0.0 , 0.0 ) ;
1916
1901
assert ! ( close( z. powc( b) , z) ) ;
1902
+ assert ! ( z. powc( Complex64 :: new( 0. , 0. ) ) . is_nan( ) ) ;
1903
+ assert ! ( z. powc( Complex64 :: new( 0. , INFINITY ) ) . is_nan( ) ) ;
1904
+ assert ! ( z. powc( Complex64 :: new( 10. , INFINITY ) ) . is_nan( ) ) ;
1905
+ assert ! ( z. powc( Complex64 :: new( INFINITY , INFINITY ) ) . is_nan( ) ) ;
1906
+ assert ! ( close( z. powc( Complex64 :: new( INFINITY , 0. ) ) , z) ) ;
1917
1907
}
1918
1908
1919
1909
#[ test]
0 commit comments