BoosterSeat  0.1
A C++ library that includes common utilities that are used in other projects.
numbers.hpp
Go to the documentation of this file.
1 #ifndef NUMBERS_HPP_
2 #define NUMBERS_HPP_
3 
4 #include <cmath>
5 #include <iomanip>
6 #include <sstream>
7 
8 namespace bst {
9 
15 double doubleToPrecisionTwo(double);
16 
28 inline bool isApproxEqual(double a, double b, double epsilon) {
29  return std::abs(a - b) <= epsilon;
30 }
31 
44 inline bool isApproxEqualPercent(const double a, const double b,
45  const double percent) {
46  return isApproxEqual(a, b, percent * std::max(a, b));
47 }
48 
49 inline std::string rndTs(double d, int precision) {
50  std::stringstream ss;
51  ss << std::fixed << std::setprecision(precision) << d;
52  return ss.str();
53 }
54 
55 } // namespace bst
56 
57 #endif /* NUMBERS_HPP_ */
Definition: filesystem.cpp:34
bool isApproxEqual(double a, double b, double epsilon)
Just a simple function to compare two doubles by a given epsilon.
Definition: numbers.hpp:28
double doubleToPrecisionTwo(double)
Rounds a double to two decimal places. For example: 1.2345 -> 1.23.
Definition: numbers.cpp:3
std::string rndTs(double d, int precision)
Definition: numbers.hpp:49
bool isApproxEqualPercent(const double a, const double b, const double percent)
Definition: numbers.hpp:44