dotnet/examples/ManagedCPP/example-Accumulator.cpp
Go to the documentation of this file.
1 using namespace System;
2 using namespace NETGeographicLib;
3 
5 {
6  try {
7  // Compare using Accumulator and ordinary summation for a sum of large and
8  // small terms.
9  double sum = 0;
10  Accumulator^ acc = gcnew Accumulator();
11  acc->Assign( 0.0 );
12  sum += 1e20; sum += 1; sum += 2; sum += 100; sum += 5000; sum += -1e20;
13  acc->Sum( 1e20 ); acc->Sum( 1 ); acc->Sum( 2 ); acc->Sum( 100 ); acc->Sum( 5000 ); acc->Sum( -1e20 );
14  Console::WriteLine(String::Format("{0} {1}", sum, acc->Result()));
15  }
16  catch (GeographicErr^ e) {
17  Console::WriteLine( String::Format( "Caught exception: {0}", e->Message ) );
18  return -1;
19  }
20  return 0;
21 }
Exception class for NETGeographicLib.
void Sum(double a)
Adds a value to the accumulator.
Definition: numpy.h:543
void Assign(double a)
Assigns a value to an accumulator.
double Result()
Returns the accumulated value.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
Definition: mpreal.h:2381
int main(array< System::String^>^)
.NET wrapper for GeographicLib::Accumulator.
Definition: Accumulator.h:44


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:02