List of usage examples for java.math BigInteger clone
@HotSpotIntrinsicCandidate protected native Object clone() throws CloneNotSupportedException;
From source file:logic.ApacheInterpolation.java
/** * Return a copy of the divided difference array. * <p>/*from w w w . jav a2s .co m*/ * The divided difference array is defined recursively by <pre> * f[x0] = f(x0) * f[x0,x1,...,xk] = (f[x1,...,xk] - f[x0,...,x[k-1]]) / (xk - x0) * </pre></p> * <p> * The computational complexity is O(N^2).</p> * * @param x Interpolating points array. * @param y Interpolating values array. * @return a fresh copy of the divided difference array. * @throws DimensionMismatchException if the array lengths are different. * @throws NumberIsTooSmallException if the number of points is less than 2. * @throws NonMonotonicSequenceException * if {@code x} is not sorted in strictly increasing order. */ protected static BigInteger[] computeDividedDifference(final double x[], final BigInteger y[]) throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException { // No need to check, the condition must be valid according to the paper // PolynomialFunctionLagrangeForm.verifyInterpolationArray(x, y, true); final BigInteger[] divdiff = y.clone(); // initialization final int n = x.length; final BigInteger[] a = new BigInteger[n]; a[0] = divdiff[0]; for (int i = 1; i < n; i++) { for (int j = 0; j < n - i; j++) { final BigInteger denominator = BigInteger.valueOf((long) (x[j + i] - x[j])); divdiff[j] = (divdiff[j + 1].subtract(divdiff[j])).divide(denominator); } a[i] = divdiff[0]; } return a; }