- Replace
x * x + y * y
withhypot(x, y)
(9feb2ea)- This prevents overflow and underflow during calculating
length
anddistance
. It makes it possible to pass the following tests.
- This prevents overflow and underflow during calculating
XCTAssertEqual(CGPoint(x: .greatestFiniteMagnitude, y: 0.0).length, .greatestFiniteMagnitude)
XCTAssertEqual(CGPoint(x: 0.0, y: .leastNonzeroMagnitude).length, .leastNonzeroMagnitude)