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 }
main
int main()
Definition: examples/example-Accumulator.cpp:10
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GeographicLib
Namespace for GeographicLib.
Definition: JacobiConformal.hpp:15
Accumulator.hpp
Header for GeographicLib::Accumulator class.
GeographicLib::Accumulator
An accumulator for sums.
Definition: Accumulator.hpp:40
std
Definition: BFloat16.h:88


gtsam
Author(s):
autogenerated on Mon Jul 1 2024 03:01:15