Re: [swift-users] FloatingPoint equality ..

2017-06-29 Thread Gavin Eadie via swift-users
.. agreed but this looks too awful (and is mostly a joke!) return a >= b.nextDown.nextDown.nextDown.nextDown && a <= b.nextUp. nextUp.nextUp.nextUp Thanks, friends, for your insights and info .. Gavin On Thu, Jun 29, 2017 at 3:30 PM, Taylor Swift via swift-users < swift-users@swift.org>

Re: [swift-users] FloatingPoint equality ..

2017-06-29 Thread Stephen Canon via swift-users
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(_ 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

[swift-users] FloatingPoint equality ..

2017-06-29 Thread Gavin Eadie via swift-users
I've spent a fascinating evening and morning in the arcane depths of floating point, specifically researching the comparison of two floating point numbers. I pretty much understand how to do this with a combination of 'epsilon' and 'ULPs' after reading this