[swift-evolution] implementing real (floating point) number comparison tolerance as a compiler directive.

Pyry Jahkola 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.)

— Pyry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160301/4d0f7824/attachment.html>

More information about the swift-evolution mailing list