Merge pull request #61 from Wildchild9/master

Fixed `Complex` division by zero to return .infinity
This commit is contained in:
Stephen Canon authored and GitHub committed 2019-11-09 15:38:50 -05:00
commit d065a84750
2 files changed
+8

No files matched your search

+1
View File
@@ -90,6 +90,7 @@ extension Complex: Numeric {
@usableFromInline @_alwaysEmitIntoClient @inline(never)
internal static func rescaledDivide(_ z: Complex, _ w: Complex) -> Complex {
if w.isZero { return .infinity }
if z.isZero || !w.isFinite { return .zero }
// TODO: detect when RealType is Float and just promote to Double, then
// use the naive algorithm.
+7
View File
@@ -177,4 +177,11 @@ final class ArithmeticTests: XCTestCase {
if checkMultiply(test.b, test.c, expected: test.a, ulps: 1.0) { XCTFail() }
}
}
func testDivisionByZero() {
XCTAssertFalse((Complex(0, 0) / Complex(0, 0)).isFinite)
XCTAssertFalse((Complex(1, 1) / Complex(0, 0)).isFinite)
XCTAssertFalse((Complex.infinity / Complex(0, 0)).isFinite)
XCTAssertFalse((Complex.i / Complex(0, 0)).isFinite)
}
}