Package net.sf.geographiclib
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.Accumulator(Accumulator a)
Construct from another Accumulator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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] + yvoid
Negate()
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).
-
-
-
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 modulusPut sum in the rangle [−y, y].
-
-