Package application.model.rules.misc
Class Summarizer
java.lang.Object
application.model.rules.misc.Summarizer
class Summarizer
extends java.lang.Object
Adds up numbers in an array with perfect precision, and in O(n).
From https://code.activestate.com/recipes/393090/
-
Constructor Summary
Constructors Constructor Description Summarizer()
-
Method Summary
Modifier and Type Method Description static double
msum(double... values)
Perfectly sums up numbers, without rounding errors (if at all possible).static double
msum(java.util.Collection<java.lang.Double> values)
Perfectly sums up numbers, without rounding errors (if at all possible).static double
sum(java.util.Collection<java.lang.Double> values)
Sums up the rest of the partial numbers which cannot be summed up without loss of precision.
-
Constructor Details
-
Summarizer
Summarizer()
-
-
Method Details
-
msum
public static double msum(double... values)Perfectly sums up numbers, without rounding errors (if at all possible).- Parameters:
values
- The values to sum up.- Returns:
- The sum.
-
msum
public static double msum(java.util.Collection<java.lang.Double> values)Perfectly sums up numbers, without rounding errors (if at all possible).- Parameters:
values
- The values to sum up.- Returns:
- The sum.
-
sum
public static double sum(java.util.Collection<java.lang.Double> values)Sums up the rest of the partial numbers which cannot be summed up without loss of precision.
-