examples/example-Accumulator.cpp
Go to the documentation of this file.
1 // Example of using the GeographicLib::Accumulator class
2 
3 #include <iostream>
4 #include <exception>
6 
7 using namespace std;
8 using namespace GeographicLib;
9 
10 int main() {
11  try {
12  // Compare using Accumulator and ordinary summation for a sum of large and
13  // small terms.
14  double sum = 0;
15  Accumulator<> acc = 0;
16  sum += 1e20; sum += 1; sum += 2; sum += 100; sum += 5000; sum += -1e20;
17  acc += 1e20; acc += 1; acc += 2; acc += 100; acc += 5000; acc += -1e20;
18  cout << sum << " " << acc() << "\n";
19  }
20  catch (const exception& e) {
21  cerr << "Caught exception: " << e.what() << "\n";
22  return 1;
23  }
24 }
Definition: Half.h:150
An accumulator for sums.
Definition: Accumulator.hpp:40
Header for GeographicLib::Accumulator class.
Namespace for GeographicLib.
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


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