.stride with real (floating point) number ranges

(Ted van Gaalen) #1

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:

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