Serguey Asael Shinder: DoubleStream.sum may use compensated summation and differ from a plain loop
These two methods look interchangeable:
double loop(double[] xs) {
double s = 0;
for (double x : xs) s += x;
return s;
}
double stream(double[] xs) {
return DoubleStream.of(xs).sum();
}

For integers they are. For double, the javadoc of DoubleStream.sum says they need not be. If floating-point addition were exact, the method "would be equivalent to return reduce(0, Double::sum);", but because it is not, that code "is not necessarily equivalent to the summation computation done by this method". The order of addition "is intentionally not defined to allow for implementation flexibility to improve the speed and accuracy of the computed result", and the method "may be implemented using compensated summation or other technique to reduce the error bound". It adds that "the output of this method may vary on the same input elements". (https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/stream/DoubleStream.html)
The loop has no such freedom. Java evaluates s += x left to right, one rounding per step, so 0.1, 0.2 and 0.3 summed in that order give the familiar 0.6000000000000001. A compensated sum keeps track of the rounding error and can return 0.6. The javadoc does not promise which one you get from the stream, so I will not claim a number either; there is no JDK on the machine I write this on, and the point is that the specification leaves it open.
Two practical consequences follow. First, a test that asserts assertEquals(loop(xs), stream(xs)) with no tolerance compares two algorithms, not two spellings of one, and can break on a JDK update or when the stream goes parallel. Compare floating-point results with a tolerance chosen for the data. Second, when results must be reproducible bit for bit, across runs, versions or services, write the summation yourself in a fixed order and document it; do not rely on an operation whose order is explicitly unspecified.
The same week Node.js 27 Alpha added Math.sumPrecise, a JavaScript method whose whole purpose is the accurate answer. Java's stream sum aims for accuracy too, but as a permission rather than a contract.