File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -420,7 +420,9 @@ extension Complex: ElementaryFunctions {
420
420
421
421
@inlinable
422
422
public static func pow( _ z: Complex , _ n: Int ) -> Complex {
423
- if z. isZero { return . zero }
423
+ if z. isZero {
424
+ return n < 0 ? . infinity : n == 0 ? . one : . zero
425
+ }
424
426
// TODO: this implementation is not quite correct, because n may be
425
427
// rounded in conversion to RealType. This only effects very extreme
426
428
// cases, so we'll leave it alone for now.
Original file line number Diff line number Diff line change @@ -399,6 +399,18 @@ final class ElementaryFunctionTests: XCTestCase {
399
399
}
400
400
}
401
401
}
402
+
403
+ func testPowR< T: Real & FixedWidthFloatingPoint > ( _ type: T . Type ) {
404
+ XCTAssertEqual ( Complex< T> . pow( . zero, - . one) , . infinity)
405
+ XCTAssertEqual ( Complex< T> . pow( . zero, . zero) , . infinity)
406
+ XCTAssertEqual ( Complex< T> . pow( . zero, + . one) , . infinity)
407
+ }
408
+
409
+ func testPowN< T: Real & FixedWidthFloatingPoint > ( _ type: T . Type ) {
410
+ XCTAssertEqual ( Complex< T> . pow( . zero, - 1 ) , . infinity)
411
+ XCTAssertEqual ( Complex< T> . pow( . zero, 0 ) , . one)
412
+ XCTAssertEqual ( Complex< T> . pow( . zero, + 1 ) , . zero)
413
+ }
402
414
403
415
func testFloat( ) {
404
416
testExp ( Float . self)
@@ -411,6 +423,8 @@ final class ElementaryFunctionTests: XCTestCase {
411
423
testAcosh ( Float . self)
412
424
testAsinh ( Float . self)
413
425
testAtanh ( Float . self)
426
+ testPowR ( Float . self)
427
+ testPowN ( Float . self)
414
428
}
415
429
416
430
func testDouble( ) {
@@ -424,6 +438,8 @@ final class ElementaryFunctionTests: XCTestCase {
424
438
testAcosh ( Double . self)
425
439
testAsinh ( Double . self)
426
440
testAtanh ( Double . self)
441
+ testPowR ( Double . self)
442
+ testPowN ( Double . self)
427
443
}
428
444
429
445
#if (arch(i386) || arch(x86_64)) && !os(Windows) && !os(Android)
@@ -438,6 +454,8 @@ final class ElementaryFunctionTests: XCTestCase {
438
454
testAcosh ( Float80 . self)
439
455
testAsinh ( Float80 . self)
440
456
testAtanh ( Float80 . self)
457
+ testPowR ( Float80 . self)
458
+ testPowN ( Float80 . self)
441
459
}
442
460
#endif
443
461
}
You can’t perform that action at this time.
0 commit comments