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

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

#include <Accumulator.h>

Public Member Functions

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

Static Public Member Functions

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

Private Member Functions

 !Accumulator (void)
 

Private Attributes

GeographicLib::Accumulator< double > * m_pAccumulator
 

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:

// Example of using the GeographicLib::Accumulator class
#include <iostream>
#include <exception>
using namespace std;
using namespace GeographicLib;
int main() {
try {
// Compare using Accumulator and ordinary summation for a sum of large and
// small terms.
double sum = 0;
Accumulator<> acc = 0;
sum += 1e20; sum += 1; sum += 2; sum += 100; sum += 5000; sum += -1e20;
acc += 1e20; acc += 1; acc += 2; acc += 100; acc += 5000; acc += -1e20;
cout << sum << " " << acc() << "\n";
}
catch (const exception& e) {
cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
}

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

◆ !Accumulator()

Accumulator::!Accumulator ( void  )
private

Definition at line 19 of file dotnet/NETGeographicLib/Accumulator.cpp.

◆ Accumulator()

Accumulator::Accumulator ( void  )

Constructor.

Definition at line 29 of file dotnet/NETGeographicLib/Accumulator.cpp.

◆ ~Accumulator()

NETGeographicLib::Accumulator::~Accumulator ( )
inline

Destructor calls the finalizer.

Definition at line 55 of file Accumulator.h.

Member Function Documentation

◆ Assign()

void Accumulator::Assign ( double  a)

Assigns a value to an accumulator.

Parameters
[in]aThe value to be assigned.

Definition at line 42 of file dotnet/NETGeographicLib/Accumulator.cpp.

◆ Multiply()

void Accumulator::Multiply ( int  i)

Multiplication by an integer.

Parameters
[in]iThe multiplier.

Definition at line 60 of file dotnet/NETGeographicLib/Accumulator.cpp.

◆ operator!=()

bool 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.

Definition at line 72 of file dotnet/NETGeographicLib/Accumulator.cpp.

◆ operator<()

bool 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.

Definition at line 78 of file dotnet/NETGeographicLib/Accumulator.cpp.

◆ operator<=()

bool 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.

Definition at line 84 of file dotnet/NETGeographicLib/Accumulator.cpp.

◆ operator==()

bool 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.

Definition at line 66 of file dotnet/NETGeographicLib/Accumulator.cpp.

◆ operator>()

bool 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.

Definition at line 90 of file dotnet/NETGeographicLib/Accumulator.cpp.

◆ operator>=()

bool 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.

Definition at line 96 of file dotnet/NETGeographicLib/Accumulator.cpp.

◆ Result()

double Accumulator::Result ( )

Returns the accumulated value.

Definition at line 48 of file dotnet/NETGeographicLib/Accumulator.cpp.

◆ Sum()

void Accumulator::Sum ( double  a)

Adds a value to the accumulator.

Parameters
[in]aThe value to be added.

Definition at line 54 of file dotnet/NETGeographicLib/Accumulator.cpp.

Member Data Documentation

◆ m_pAccumulator

GeographicLib::Accumulator<double>* NETGeographicLib::Accumulator::m_pAccumulator
private

Definition at line 48 of file Accumulator.h.


The documentation for this class was generated from the following files:
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GeographicLib
Namespace for GeographicLib.
Definition: JacobiConformal.hpp:15
main
int main(int argc, char **argv)
Definition: cmake/example_cmake_find_gtsam/main.cpp:63
Accumulator.hpp
Header for GeographicLib::Accumulator class.
GeographicLib::Accumulator
An accumulator for sums.
Definition: Accumulator.hpp:40
std
Definition: BFloat16.h:88
args
Definition: pytypes.h:2210
NETGeographicLib
Definition: Accumulator.h:13
NETGeographicLib::Accumulator::Accumulator
Accumulator(void)
Constructor.
Definition: dotnet/NETGeographicLib/Accumulator.cpp:29


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:25:00