mirror of
https://github.com/apple/swift-numerics
synced 2026-11-29 05:24:24 +00:00
Merge pull request #61 from Wildchild9/master
Fixed `Complex` division by zero to return .infinity
This commit is contained in:
2 files changed
+8
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user