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: BFloat16.h:88
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.)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:12