ON_Sum Class Reference

Class for carefully adding long list of numbers. More...

#include <opennurbs_math.h>

Public Member Functions

 ON_Sum ()
 Creates a sum that is ready to be used. More...
 
void Begin (double starting_value=0.0)
 If a sum is being used more than once, call Begin() before starting each sum. More...
 
void operator+= (double x)
 Calls ON_Sum::Plus(x); More...
 
void operator-= (double x)
 Calls ON_Sum::Plus(-x); More...
 
void operator= (double x)
 Calls ON_Sum::Begin(x) More...
 
void Plus (double x)
 Add x to the current sum. More...
 
void Plus (double x, double dx)
 Add x to the current sum. More...
 
int SummandCount () const
 
double Total (double *error_estimate=nullptr)
 Calculates the total sum. More...
 

Detailed Description

Class for carefully adding long list of numbers.

Constructor & Destructor Documentation

◆ ON_Sum()

ON_Sum::ON_Sum ( )

Creates a sum that is ready to be used.

Member Function Documentation

◆ Begin()

void ON_Sum::Begin ( double  starting_value = 0.0)

If a sum is being used more than once, call Begin() before starting each sum.

Parameters
starting_value[in] Initial value of sum.

◆ operator+=()

void ON_Sum::operator+= ( double  x)

Calls ON_Sum::Plus(x);

◆ operator-=()

void ON_Sum::operator-= ( double  x)

Calls ON_Sum::Plus(-x);

◆ operator=()

void ON_Sum::operator= ( double  x)

Calls ON_Sum::Begin(x)

◆ Plus() [1/2]

void ON_Sum::Plus ( double  x)

Add x to the current sum.

Parameters
x[in] value to add to the current sum.

◆ Plus() [2/2]

void ON_Sum::Plus ( double  x,
double  dx 
)

Add x to the current sum.

Parameters
x[in] value to add to the current sum.
dx[in] symmetric uncertainty in x. (true value is in the range x-dx to x+dx

◆ SummandCount()

int ON_Sum::SummandCount ( ) const
Returns
Number of summands.

◆ Total()

double ON_Sum::Total ( double *  error_estimate = nullptr)

Calculates the total sum.

Parameters
error_estimate[out] if not nullptr, the returned value of *error_estimate is an estimate of the error in the sum.
Returns
Total of the sum.

You can get subtotals by mixing calls to Plus() and Total(). In delicate sums, some precision may be lost in the final total if you call Total() to calculate subtotals.