[swift-users] FloatingPoint equality ..

Stephen Canon scanon at apple.com
Thu Jun 29 13:55:57 CDT 2017

I should also point out:

(a) your code can be somewhat simpler in Swift. I would probably write something along the lines of:

func almostEqual<T: FloatingPoint>(_ a: T, _ b: T) -> Bool {
    return a >= b.nextDown && a <= b.nextUp

(b) one ULP is almost never a tolerance you want to use. It’s much too small for almost all computations, and too large for most of the remaining ones.

– Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170629/0f5c184e/attachment.html>

More information about the swift-users mailing list