kcl.waterloo.math
Class fp
- java.lang.Object
-
- kcl.waterloo.math.fp
-
public class fp extends java.lang.ObjectProvides static methods for double arithmetic with corrections for loss of precision. See:Fast and Accurate Computation of Sum and Dot Product
orAccurate Computation of Sum and Dot Product [NOTE TYPO IN THE TWOSUM ALGORITHM IN THIS ONE]
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static double[]cusum(double[] in)Returns the cumulative sum of the elements of the input using Knuth's correction to accumulate the error.static double[]cusumi(double[] in)Returns the cumulative sum of the elements of the input using Knuth's correction to accumulate the error (in-place).static doubledot(double[] a, double[] b)Returns the dot product.static double[]split(double val)Splits a double value into two double values where the sum of the two is the input.static doublesum(double[] in)Returns the sum ofinusing Knuth's correction to accumulate the error.static doublesum(double[] in, int idx0, int idx1)Returns the sum between two indices (inclusive).static booleantolEquals(double a, double b, double tol)static double[]twoProduct(double a, double b)Returns the product of two double values and a correction for loss of precision in the multiplication.static double[]twoSum(double a, double b)Returns the sum of two double values and a correction for loss of precision in the summation.
-
-
-
Method Detail
-
split
public static double[] split(double val)
Splits a double value into two double values where the sum of the two is the input. See T. J. Dekker, A floating-point technique for extending the available precision, Numer. Math., 18 (1971), pp. 224-242.- Parameters:
val- a double input- Returns:
- a double[2] array - where the sum of values==the input.
-
twoProduct
public static double[] twoProduct(double a, double b)Returns the product of two double values and a correction for loss of precision in the multiplication.- Parameters:
a- a double value.b- a double value.- Returns:
- a double[2] array containing in [0]: the product, and in [1]: the required correction.
-
twoSum
public static double[] twoSum(double a, double b)Returns the sum of two double values and a correction for loss of precision in the summation.- Parameters:
a- a double value.b- a double value.- Returns:
- a double[2] array containing in [0]: the sum, and in [1]: the required correction.
-
sum
public static double sum(double[] in)
Returns the sum ofinusing Knuth's correction to accumulate the error. The accumulated error is added to the output.- Parameters:
in-- Returns:
- the sum
-
sum
public static double sum(double[] in, int idx0, int idx1)Returns the sum between two indices (inclusive).- Parameters:
in- input arrayidx0- start indexidx1- end index- Returns:
- the sum of in[idx0] thtough in[idx1]
-
cusum
public static double[] cusum(double[] in)
Returns the cumulative sum of the elements of the input using Knuth's correction to accumulate the error. The accumulated error for each element is added to the output.- Parameters:
in-- Returns:
- a double[]
-
cusumi
public static double[] cusumi(double[] in)
Returns the cumulative sum of the elements of the input using Knuth's correction to accumulate the error (in-place). The accumulated error for each element is added to the output.- Parameters:
in-- Returns:
- a double[]
-
dot
public static double dot(double[] a, double[] b)Returns the dot product.- Parameters:
a- double[] input ab- double[] input b- Returns:
- the sum of a[k]*b[k] for k = 0 .. length(a)-1
-
tolEquals
public static boolean tolEquals(double a, double b, double tol)
-
-
DMelt 3.0 © DataMelt by jWork.ORG