Primitive streams

Joe Darcy joe.darcy at oracle.com
Mon Dec 31 10:23:49 PST 2012


On 12/29/2012 10:00 AM, Remi Forax wrote:
> On 12/28/2012 06:55 PM, Brian Goetz wrote:
>

[snip]

>>
>>
>> 3.  Numerics.  Adding up doubles is not as simple as reducing with 
>> Double::sum (unless you don't care about accuracy.)  Having methods 
>> for numeric sums gives us a place to put such intelligence; general 
>> reduce does not.
>
> I'm always afraid when someone try to put "intelligence" in a program. 
> We never have the same.
>

Just adding up floating-point numbers is a subtle and interesting topic 
of study.  For example, there is a whole chapter on this matter in 
Nicholas Higham's "Accuracy and Stability of Numerical Algorithms."

While Java is distinguished by its *predictable* floating-point 
semantics, just adding my a sequence of double numbers as "a + b" 
without any further processing or state can yield very poor numerical 
results.  Therefore, I think it is more prudent if we could say 
something like "this summation of double numbers must have an error 
bound less than x" where x is in part a function of the number of input 
values.  This is analogous to the quality of implementation requirements 
found in the java.lang.Math class which allow for alternative 
implementations of sin, cos, etc.

-Joe


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