NETGeographicLib  1.47
Public Member Functions | Static Public Member Functions | List of all members
NETGeographicLib::Accumulator Class Reference

.NET wrapper for GeographicLib::Accumulator. More...

#include <NETGeographicLib/Accumulator.h>

Public Member Functions

 Accumulator (void)
 Constructor. More...
 
 ~Accumulator ()
 Destructor calls the finalizer. More...
 
void Assign (double a)
 Assigns a value to an accumulator. More...
 
double Result ()
 Returns the accumulated value. More...
 
void Sum (double a)
 Adds a value to the accumulator. More...
 
void Multiply (int i)
 Multiplication by an integer. More...
 

Static Public Member Functions

static bool operator== (Accumulator^ lhs, double a)
 Equality operator. More...
 
static bool operator!= (Accumulator^ lhs, double a)
 Inequality operator. More...
 
static bool operator< (Accumulator^ lhs, double a)
 Less than operator. More...
 
static bool operator<= (Accumulator^ lhs, double a)
 Less than or equal to operator. More...
 
static bool operator> (Accumulator^ lhs, double a)
 Greater than operator. More...
 
static bool operator>= (Accumulator^ lhs, double a)
 Greater than or equal to operator. More...
 

Detailed Description

.NET wrapper for GeographicLib::Accumulator.

This class allows .NET applications to access GeographicLib::Accumulator<double>.

This allow many numbers of floating point type double to be added together with twice the normal precision. 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).

C# Example:

using System;
namespace example_Accumulator
{
class Program
{
static void Main(string[] args)
{
try {
// Compare using Accumulator and ordinary summation for a sum of large and
// small terms.
double sum = 0;
Accumulator acc = new Accumulator();
acc.Assign( 0.0 );
sum += 1e20; sum += 1; sum += 2; sum += 100; sum += 5000; sum += -1e20;
acc.Sum( 1e20 ); acc.Sum( 1 ); acc.Sum( 2 ); acc.Sum( 100 ); acc.Sum( 5000 ); acc.Sum( -1e20 );
Console.WriteLine(String.Format("{0} {1}", sum, acc.Result()));
}
catch (GeographicErr e) {
Console.WriteLine( String.Format( "Caught exception: {0}", e.Message ) );
}
}
}
}

Managed C++ Example:

using namespace System;
using namespace NETGeographicLib;
int main(array<System::String ^> ^/*args*/)
{
try {
// Compare using Accumulator and ordinary summation for a sum of large and
// small terms.
double sum = 0;
Accumulator^ acc = gcnew Accumulator();
acc->Assign( 0.0 );
sum += 1e20; sum += 1; sum += 2; sum += 100; sum += 5000; sum += -1e20;
acc->Sum( 1e20 ); acc->Sum( 1 ); acc->Sum( 2 ); acc->Sum( 100 ); acc->Sum( 5000 ); acc->Sum( -1e20 );
Console::WriteLine(String::Format("{0} {1}", sum, acc->Result()));
}
catch (GeographicErr^ e) {
Console::WriteLine( String::Format( "Caught exception: {0}", e->Message ) );
return -1;
}
return 0;
}

Visual Basic Example:

Imports NETGeographicLib
Module example_Accumulator
Public Sub Main()
Try
' Compare using Accumulator and ordinary summation for a sum of large and
' small terms.
Dim sum As Double = 0.0
Dim acc As Accumulator = New Accumulator()
acc.Assign(0.0)
sum += 1.0E+20 : sum += 1 : sum += 2 : sum += 100 : sum += 5000
sum += -1.0E+20 : acc.Sum(1.0E+20) : acc.Sum(1) : acc.Sum(2) : acc.Sum(100) : acc.Sum(5000) : acc.Sum(-1.0E+20)
Console.WriteLine(String.Format("{0} {1}", sum, acc.Result()))
Catch ex As GeographicErr
Console.WriteLine(String.Format("Caught exception: {0}", ex.Message))
End Try
End Sub
End Module

INTERFACE DIFFERENCES:
Since assignment operators (=,+=,-=,*=) are not supported in managed classes;

Use Result() instead of the () operator to obtain the summed value from the accumulator.

Definition at line 44 of file Accumulator.h.

Constructor & Destructor Documentation

NETGeographicLib::Accumulator::Accumulator ( void  )

Constructor.

Referenced by ~Accumulator().

NETGeographicLib::Accumulator::~Accumulator ( )
inline

Destructor calls the finalizer.

Definition at line 55 of file Accumulator.h.

References Accumulator(), Assign(), Multiply(), operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), Result(), and Sum().

Member Function Documentation

void NETGeographicLib::Accumulator::Assign ( double  a)

Assigns a value to an accumulator.

Parameters
[in]aThe value to be assigned.

Referenced by ~Accumulator().

double NETGeographicLib::Accumulator::Result ( )

Returns the accumulated value.

Referenced by ~Accumulator().

void NETGeographicLib::Accumulator::Sum ( double  a)

Adds a value to the accumulator.

Parameters
[in]aThe value to be added.

Referenced by ~Accumulator().

void NETGeographicLib::Accumulator::Multiply ( int  i)

Multiplication by an integer.

Parameters
[in]iThe multiplier.

Referenced by ~Accumulator().

static bool NETGeographicLib::Accumulator::operator== ( Accumulator lhs,
double  a 
)
static

Equality operator.

Parameters
[in]lhsThe accumulator.
[in]aThe value to be compared to.
Returns
true if the accumulated value is equal to a.

Referenced by ~Accumulator().

static bool NETGeographicLib::Accumulator::operator!= ( Accumulator lhs,
double  a 
)
static

Inequality operator.

Parameters
[in]lhsThe accumulator.
[in]aThe value to be compared to.
Returns
true if the accumulated value is not equal to a.

Referenced by ~Accumulator().

static bool NETGeographicLib::Accumulator::operator< ( Accumulator lhs,
double  a 
)
static

Less than operator.

Parameters
[in]lhsThe accumulator.
[in]aThe value to be compared to.
Returns
true if the accumulated value is less than a.

Referenced by ~Accumulator().

static bool NETGeographicLib::Accumulator::operator<= ( Accumulator lhs,
double  a 
)
static

Less than or equal to operator.

Parameters
[in]lhsThe accumulator.
[in]aThe value to be compared to.
Returns
true if the accumulated value is less than or equal to a.

Referenced by ~Accumulator().

static bool NETGeographicLib::Accumulator::operator> ( Accumulator lhs,
double  a 
)
static

Greater than operator.

Parameters
[in]lhsThe accumulator.
[in]aThe value to be compared to.
Returns
true if the accumulated value is greater than a.

Referenced by ~Accumulator().

static bool NETGeographicLib::Accumulator::operator>= ( Accumulator lhs,
double  a 
)
static

Greater than or equal to operator.

Parameters
[in]lhsThe accumulator.
[in]aThe value to be compared to.
Returns
true if the accumulated value is greater than or equal to a.

Referenced by ~Accumulator().


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