NETGeographicLib::Accumulator Class Reference

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

#include <NETGeographicLib/Accumulator.h>

List of all members.

Public Member Functions

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

Static Public Member Functions

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

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;
using NETGeographicLib;

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().


Member Function Documentation

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

Assigns a value to an accumulator.

Parameters:
[in] a The value to be assigned.
double NETGeographicLib::Accumulator::Result (  ) 

Returns the accumulated value.

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

Adds a value to the accumulator.

Parameters:
[in] a The value to be added.
void NETGeographicLib::Accumulator::Multiply ( int  i  ) 

Multiplication by an integer.

Parameters:
[in] i The multiplier.
static bool NETGeographicLib::Accumulator::operator== ( Accumulator^   lhs,
double  a 
) [static]

Equality operator.

Parameters:
[in] lhs The accumulator.
[in] a The value to be compared to.
Returns:
true if the accumulated value is equal to a.
static bool NETGeographicLib::Accumulator::operator!= ( Accumulator^   lhs,
double  a 
) [static]

Inequality operator.

Parameters:
[in] lhs The accumulator.
[in] a The value to be compared to.
Returns:
true if the accumulated value is not equal to a.
static bool NETGeographicLib::Accumulator::operator< ( Accumulator^   lhs,
double  a 
) [static]

Less than operator.

Parameters:
[in] lhs The accumulator.
[in] a The value to be compared to.
Returns:
true if the accumulated value is less than a.
static bool NETGeographicLib::Accumulator::operator<= ( Accumulator^   lhs,
double  a 
) [static]

Less than or equal to operator.

Parameters:
[in] lhs The accumulator.
[in] a The value to be compared to.
Returns:
true if the accumulated value is less than or equal to a.
static bool NETGeographicLib::Accumulator::operator> ( Accumulator^   lhs,
double  a 
) [static]

Greater than operator.

Parameters:
[in] lhs The accumulator.
[in] a The value to be compared to.
Returns:
true if the accumulated value is greater than a.
static bool NETGeographicLib::Accumulator::operator>= ( Accumulator^   lhs,
double  a 
) [static]

Greater than or equal to operator.

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

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends

Generated on 6 Oct 2014 for NETGeographicLib by  doxygen 1.6.1