[swift-evolution] implementing real (floating point) number comparison tolerance as a compiler directive.
pyry.jahkola at iki.fi
Tue Mar 1 13:39:08 CST 2016
> On 01 Mar 2016, at 20:28, ted van gaalen via swift-evolution <swift-evolution at swift.org> wrote:
> in relation to my message about handling floating point number comparisation tolerance in e.g. a .stride function, wouldn't this be better handled by a compiler directive?
> For example:
> @floatingPointComparisonTolerance = 0.001
I don't think it's a good idea. That directive would break the transitivity requirement of Equatable (the last line below):
/// **Equality is an equivalence relation**
/// - `x == x` is `true`
/// - `x == y` implies `y == x`
/// - `x == y` and `y == z` implies `x == z`
You might want to define another operator or function for approximately equal instead.
(Not like equality wasn't already broken for floats because of NaN, but at least we can try to keep the remaining semantics sane.)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution