Fwd: JDK 9 RFR of JDK-8030942: Explicitly state floating-point summation requirements on non-finite inputs (original) (raw)

Georgiy Rakov georgiy.rakov at oracle.com
Fri Jul 18 19:00:50 UTC 2014


On 18.07.2014 20:14, Joe Darcy wrote:

Hello Georgiy,

On 07/18/2014 05:29 AM, Georgiy Rakov wrote: Hello Joe,

could you please clarify by short example following assertion: 154 * If the exact sum is infinite, a properly-signed infinity is 155 * returned. I'm afraid I don't quite understand what you mean here by 'exact sum'. By "exact sum," the sum absent any floating-point rounding, the sum you would get using infinite precision to operate on the values in question. The sentence in question is intended to be a short way of saying "If you have same-signed infinities in your input, the result will be an infinity of that sign." In particular, this disallows the behavior that was fixed before JDK 8 GA where having infinities in the input would cause a NaN to be returned because of how the compensated summation code manipulated those values. Thanks, I see, however it seems to me a bit confusing, since the term "infinite exact sum" seems to me not obvious and I believe it needs some definition. I'd like to suggest to use more straightforward approach, that is as you've said: "If you have same-signed infinities in your input, the result will be an infinity of that sign.". I believe it would be more clear for end user (at least for me :)) and from conformance point of view.

Besides it seems to me a bit questionable. For instance "inexact some" looks like more appropriate, since overflowing to infinity occurs when _actual _sum exceeds the limit. By actual sum I mean sum resulted from actual summation with all the rounding happened. There wouldn't be such questions, provided straightforward approach is used.

Thanks, Georgiy.

HTH,

-Joe

Thank you, Georgiy. On 16.07.2014 16:37, Paul Sandoz wrote:

Begin forwarded message: *From: *Joe Darcy <joe.darcy at oracle.com <mailto:joe.darcy at oracle.com>> *Subject: **JDK 9 RFR of JDK-8030942: Explicitly state floating-point summation requirements on non-finite inputs* *Date: *July 16, 2014 2:29:46 AM GMT+02:00 *To: *Core-Libs-Dev <core-libs-dev at openjdk.java.net_ _<mailto:core-libs-dev at openjdk.java.net>> Hello, Please review my changes to address: JDK-8030942: Explicitly state floating-point summation requirements on non-finite inputs http://cr.openjdk.java.net/~darcy/8030942.0/ <http://cr.openjdk.java.net/%7Edarcy/8030942.0/> Patch below. Thanks, -Joe --- old/src/share/classes/java/util/DoubleSummaryStatistics.java 2014-07-15 17:26:41.000000000 -0700 +++ new/src/share/classes/java/util/DoubleSummaryStatistics.java 2014-07-15 17:26:41.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -129,9 +129,6 @@ * Returns the sum of values recorded, or zero if no values have been * recorded. * - * If any recorded value is a NaN or the sum is at any point a NaN - * then the sum will be NaN. - * *

The value of a floating-point sum is a function both of the

* input values as well as the order of addition operations. The * order of addition operations of this method is intentionally @@ -143,6 +140,23 @@ * numerical sum compared to a simple summation of {@code double} * values. * + *

If any recorded value is a NaN or the intermediate sum is at

+ * any point a NaN, then the final sum will be NaN. + * + * If the recorded values contain infinities of opposite sign, the + * final sum will be NaN. + * + * It is possible for intermediate sums of finite values to + * overflow into opposite-signed infinities; if that occurs, the + * final sum will be NaN even if the recorded values are all + * finite. + * + * If the exact sum is infinite, a properly-signed infinity is + * returned. + * + * If all the recorded values are zero, the sign of zero is + * not guaranteed to be preserved in the final sum. + * * @apiNote Values sorted by increasing absolute magnitude tend to yield * more accurate results. * @@ -193,9 +207,6 @@ * Returns the arithmetic mean of values recorded, or zero if no * values have been recorded. * - * If any recorded value is a NaN or the sum is at any point a NaN - * then the average will be code NaN. - * *

The average returned can vary depending upon the order in

* which values are recorded. * @@ -203,6 +214,10 @@ * other technique to reduce the error bound in the {@link #getSum * numerical sum} used to compute the average. * + *

This method can return a NaN or infinite result in the same

+ * kind of numerical situations as {@linkplain #getSum() the sum} + * can be NaN or infinite, respectively. + * * @apiNote Values sorted by increasing absolute magnitude tend to yield * more accurate results. * --- old/src/share/classes/java/util/stream/DoubleStream.java 2014-07-15 17:26:42.000000000 -0700 +++ new/src/share/classes/java/util/stream/DoubleStream.java 2014-07-15 17:26:42.000000000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -470,10 +470,7 @@ * code is not necessarily equivalent to the summation computation * done by this method. * - *

If any stream element is a NaN or the sum is at any

point a NaN - * then the sum will be NaN. - * - * The value of a floating-point sum is a function both + *

The value of a floating-point sum is a function both

* of the input values as well as the order of addition * operations. The order of addition operations of this method is * intentionally not defined to allow for implementation @@ -485,6 +482,23 @@ * numerical sum compared to a simple summation of {@code double} * values. * + *

If any stream element is a NaN or the intermediate sum is at

+ * any point a NaN, then the final sum will be NaN. + * + * If the stream elements contain infinities of opposite sign, the + * final sum will be NaN. + * + * It is possible for intermediate sums of finite values to + * overflow into opposite-signed infinities; if that occurs, the + * final sum will be NaN even if the stream elements are all + * finite. + * + * If the exact sum is infinite, a properly-signed infinity is + * returned. + * + * If all the stream elements are zero, the sign of zero is + * not guaranteed to be preserved in the final sum. + * *

This is a terminal

* operation. * @@ -555,9 +569,6 @@ * mean of elements of this stream, or an empty optional if this * stream is empty. * - * If any recorded value is a NaN or the sum is at any point a NaN - * then the average will be NaN. - * *

The average returned can vary depending upon the order in

* which values are recorded. * @@ -565,6 +576,10 @@ * other technique to reduce the error bound in the {@link #sum * numerical sum} used to compute the average. * + *

This method can return a NaN or infinite result in the same

+ * kind of numerical situations as {@linkplain #sum() the sum} can + * be NaN or infinite, respectively. + * *

The average is a special case of a <a_ _* href="package-summary.html#Reduction">reduction.

*



More information about the core-libs-dev mailing list