ThreeB 1.1
Public Member Functions | Public Attributes | Private Attributes
Kahan Class Reference

Class implementing the Kahan summation algorithm to allow accurate summation of very large numbers of doubles. More...

List of all members.

Public Member Functions

 Kahan ()
void add (double i)

Public Attributes

double sum

Private Attributes

double y
double c
double t

Detailed Description

Class implementing the Kahan summation algorithm to allow accurate summation of very large numbers of doubles.

Definition at line 226 of file multispot5.cc.


Constructor & Destructor Documentation

Kahan::Kahan ( ) [inline]

Definition at line 234 of file multispot5.cc.

        :c(0),sum(0)
        {}

Member Function Documentation

void Kahan::add ( double  i) [inline]

Add a number to the running sum.

Parameters:
iNumber to add

Definition at line 240 of file multispot5.cc.

Referenced by NegativeFreeEnergy::compute_with_mask(), and NegativeFreeEnergy::operator()().

        {
            //y = input -c
            y = i;
            y-= c;

            //t = sum + y
            t = sum;
            t += y;
            
            //c = (t - sum) - y
            //c = ((sum + y) - sum) - y)
            c = t;
            c -= sum;
            c -= y;
            sum = t;
        }

Member Data Documentation

double Kahan::y [private]

Input with the compensation removed. Temporary working space.

Definition at line 228 of file multispot5.cc.

double Kahan::c [private]

Running compenstation for low-order bits.

Definition at line 229 of file multispot5.cc.

double Kahan::t [private]

y + sum, which loses low order bits of y. Temporary working space.

Definition at line 230 of file multispot5.cc.

double Kahan::sum

running sum

Definition at line 232 of file multispot5.cc.


The documentation for this class was generated from the following file: