VCCC  2024.05
VisualCamp Common C++ library
epsilon.hpp
Go to the documentation of this file.
1 # /*
2 # * Created by YongGyu Lee on 2020/12/08.
3 # */
4 #
5 # ifndef VCCC_MATH_EPSILON_HPP
6 # define VCCC_MATH_EPSILON_HPP
7 #
8 # include <cmath>
9 # include <limits>
10 
11 namespace vccc {
12 
15 
30 // TODO: rename this to be meant 'machine epsilon for numerical derivation'
31 template<typename T>
32 inline T epsilon() {
33  static const auto e = static_cast<T>(std::cbrt(std::numeric_limits<T>::epsilon()));
34  return e;
35 }
36 
47 template<std::size_t i,
48  typename Tuple, typename T>
49 constexpr inline auto
50 addEpsilon(Tuple vars, T epsilon)
51 {
52  std::get<i>(vars) += std::get<i>(vars) == 0 ? epsilon : std::get<i>(vars) * epsilon;
53  return vars;
54 }
55 
57 
58 } // namespace vccc
59 
60 # endif // VCCC_MATH_EPSILON_HPP
constexpr T e
the mathematical constant
Definition: constants.hpp:37
T epsilon()
Get machine epsilon for the given type.
Definition: epsilon.hpp:32
constexpr auto addEpsilon(Tuple vars, T epsilon)
Increase the value by small amount.
Definition: epsilon.hpp:50
Definition: directory.h:12