Class Accumulator

java.lang.Object
net.sf.geographiclib.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 Summary

    Constructors
    Constructor
    Description
    Accumulator(double y)
    Construct from a double.
    Construct from another Accumulator.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add(double y)
    Add a number to the accumulator.
    static void
    AddInternal(Pair p, double s, double t, double y)
    Internal version of Add, p = [s, t] + y
    void
    Negate an accumulator.
    void
    Remainder(double y)
    Take the remainder.
    void
    Set(double y)
    Set the value to a double.
    double
    Sum()
    Return the value held in the accumulator.
    double
    Sum(double y)
    Return the result of adding a number to sum (but don't change sum).

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • 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 Details

    • 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:
      p - output Pair(s, t) with the result.
      s - the larger part of the accumulator.
      t - the smaller part of the accumulator.
      y - the addend.
    • 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].