Ranges redux

Paul Sandoz paul.sandoz at oracle.com
Mon May 13 06:48:38 PDT 2013


On May 13, 2013, at 3:02 PM, Tim Peierls <tim at peierls.net> wrote:
> On Mon, May 13, 2013 at 6:30 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
> Sequentially DoubleStream.range is currently equivalent to the following:
> 
>      *     long size = (long) Math.ceil((startInclusive - endExclusive) / step);
>      *     long i = 0
>      *     for (double v = startInclusive; i < size; i++, v = startInclusive + step * i) {
>      *         ...
>      *     }
> 
> If startInclusive + step * size == endExclusive then the range could be closed, otherwise half-open. 
> 
> Is that a reasonable expectation?
> 
> This feels like it would surprise people more often than not.
> 

Here is what Mathematica does for Range[0.0, 1.0, 1 / 3] vs. Range[0.0, 1.0 - 0.01, 1 / 3]:

http://www.wolframalpha.com/input/?i=Range%5B0.0%2C+1.0%2C+1+%2F+3%5D+vs.+Range%5B0.0%2C+1.0+-+0.01%2C+1+%2F+3%5D

R appears to do the same, you can experiment with:

http://alpha.kloudstat.com/index.php?do=/console/

  seq(0.0, 1.0, by=1/3)

However, i am struggling to find more precise details on the implementations of the above for inexact values and the upper bound.

Perhaps the best thing to do is get out of the way and let numerical libraries integrate with streams...

Paul.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/lambda-libs-spec-experts/attachments/20130513/55155294/attachment.html 


More information about the lambda-libs-spec-experts mailing list