[swift-evolution] .stride with real (floating point) number ranges

ted van gaalen tedvgiosdev at gmail.com
Tue Mar 1 06:24:17 CST 2016


Hello Erica, you're right about this, adding, what you call an epsilon value to the end value in  .stride is indeed not very elegant, a "hack", so to speak. At least for the stride function, and also with possible other statements, the solution I bring forward here to solve this problem in a simple way is to specify a tolerance factor, like so: 

0.0.stride( to: 100.0, by 0.1, comparisonTolerance: 0.01)



This is very easy to implement in the stride function.

Comparison tolerance for real numbers was introduced a long time ago,
for instance in APL. as described here, in this excellent example:
http://www.dyalog.com/uploads/documents/Papers/tolerant_comparison/tolerant_comparison.htm

In APL, this is implemented workspace-wide, not individually for each function. 
One could consider using this facility on wider scope e.g. for a complete class or file scope.

As a side note, nevertheless to be considered as very important, I'd like to highly recommend for all of us here to study if possible all program languages (not only the ones one likes) which is a great source for inspiration and also to prevent reinventing the wheel again (not meant cynically here) E.g. the comparision tolerance as described above, was already present in VS APL on IBM mainframe systems more than fourty years ago...

Since ca 1978, I have been working with many programming languages and many different insights, viewing angles. I would also like to recommend a more pragmatical approach and not being all too dogmatic. 




kind regards
Ted

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


More information about the swift-evolution mailing list