RFR: 8153293 - Stream API: Preserve SORTED and DISTINCT characteristics for boxed() and asLongStream() operations

Paul Sandoz paul.sandoz at oracle.com
Wed Apr 6 15:48:53 UTC 2016


> On 4 Apr 2016, at 21:28, Stefan Zobel <spliterator at gmail.com> wrote:
> 
> Hi Tagir,
> 
> good catch! I like the proposal.
> 

Me too. +1.

Extra bonus points to test, in addition to the tested characteristics, that the boxed/converted elements remain sorted/distinct :-)


>> 
>> (different longs can be converted into the same double, so DISTINCT is
>> not preserved here; not sure whether this is possible for ints)
>> 
> 
> I think IntStream.asDoubleStream() can also preserve DISTINCT as
> different ints can't be mapped to the same double.
> 

Yes, there are 53 bits to play with, which is more than enough to exactly represent the full range of int values.

Paul.

> 
> Math.ulp((double) Integer.MIN_VALUE) ~ 4.7E-7
> 
> in contrast to
> 
> Math.ulp((double) Long.MIN_VALUE) = 2048.0
> 
> 
> So there are more than enough doubles in the vicinity of large int
> values. It's only when ulp get's >= 1.0 that distinct integral values
> need to be mapped to the same double (that happens between 1.0E15 and
> 1.0E16 for longs). Please anyone correct me if I'm wrong.
> 
> 
> Regards,
> Stefan
> 



More information about the core-libs-dev mailing list