[swift-evolution] [pitch] Comparison Reform

Tino Heth 2th at gmx.de
Sun Apr 23 09:16:30 CDT 2017


> (Sometimes I think there should be a separate Real type that ordinary
> users work with, leaving all the fun of FP to hard-core numericists).

Might be a good idea not only because of NaN:
One of the first lessons in numerical analysis is that equality is brittle for floats, thus you check the magnitude of their delta instead.

For advanced users this is only tedious, but newbies in the field of software development often have to learn the hard way.
The whole problem could be avoided easily, but sadly, there is no obvious choice for the tolerance of the check — unless Swift adds support for generic value parameters, which could be used to define something like
typealias Velocity = FloatingPoint<precision: 0.01>
Such a type would break some mathematical rules, but hey, if a == sqrt(a) * sqrt(a) can be false, why not use a type that violates a == b => !(a < b) && !(a > b), but in exchange offers some nice convenience?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170423/32f46ee5/attachment.html>


More information about the swift-evolution mailing list