LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
constexpr_math.h
Go to the documentation of this file.
1 
10 #ifndef LARDATAALG_UTILITIES_CONSTEXPR_MATH_H
11 #define LARDATAALG_UTILITIES_CONSTEXPR_MATH_H
12 
13 namespace util {
14 
15  // --- BEGIN simple mathematical functions -----------------------------------
18 
38  // this bizarre implementation is supposed to guarantee that `abs(-0)` is `0`
39  template <typename T>
40  constexpr auto abs(T v)
41  {
42  return (-T(0) < v) ? v : -v;
43  }
44 
46 
47  // --- END simple mathematical functions -------------------------------------
48 
49 } // namespace util
50 
51 #endif // LARDATAALG_UTILITIES_CONSTEXPR_MATH_H
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:26
constexpr auto abs(T v)
Returns the absolute value of the argument.