Class Accumulator


  • public class Accumulator
    extends Object
    An accumulator for sums.

    This allow many double precision numbers to be added together with twice the normal precision. Thus the effective precision of the sum is 106 bits or about 32 decimal places.

    The implementation follows J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3) 305–363 (1997).

    In the documentation of the member functions, sum stands for the value currently held in the accumulator.

    • Constructor Detail

      • Accumulator

        public Accumulator​(double y)
        Construct from a double.

        Parameters:
        y - set sum = y.
      • Accumulator

        public Accumulator​(Accumulator a)
        Construct from another Accumulator.

        Parameters:
        a - set sum = a.
    • Method Detail

      • Set

        public void Set​(double y)
        Set the value to a double.

        Parameters:
        y - set sum = y.
      • Sum

        public double Sum()
        Return the value held in the accumulator.

        Returns:
        sum.
      • Sum

        public double Sum​(double y)
        Return the result of adding a number to sum (but don't change sum).

        Parameters:
        y - the number to be added to the sum.
        Returns:
        sum + y.
      • AddInternal

        public static void AddInternal​(Pair p,
                                       double s,
                                       double t,
                                       double y)
        Internal version of Add, p = [s, t] + y

        Parameters:
        s - the larger part of the accumulator.
        t - the smaller part of the accumulator.
        y - the addend.
        p - output Pair(s, t) with the result.
      • Add

        public void Add​(double y)
        Add a number to the accumulator.

        Parameters:
        y - set sum += y.
      • Negate

        public void Negate()
        Negate an accumulator.

        Set sum = −sum.

      • Remainder

        public void Remainder​(double y)
        Take the remainder.

        Parameters:
        y - the modulus

        Put sum in the rangle [−y, y].