Skip to content

Avoid overflow and underflow of `length` and `distance`

Latest
Compare
Choose a tag to compare
@koher koher released this 04 May 16:26
· 1 commit to master since this release
f6bed1d
  • Replace x * x + y * y with hypot(x, y) (9feb2ea)
    • This prevents overflow and underflow during calculating length and distance. It makes it possible to pass the following tests.
XCTAssertEqual(CGPoint(x: .greatestFiniteMagnitude, y: 0.0).length, .greatestFiniteMagnitude)
XCTAssertEqual(CGPoint(x: 0.0, y: .leastNonzeroMagnitude).length, .leastNonzeroMagnitude)