Thrill  0.1
abs_diff.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/math/abs_diff.hpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2017 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #ifndef TLX_MATH_ABS_DIFF_HEADER
12 #define TLX_MATH_ABS_DIFF_HEADER
13 
14 namespace tlx {
15 
16 //! \addtogroup tlx_math
17 //! \{
18 
19 /******************************************************************************/
20 // abs_diff() - calculate absolute difference
21 
22 //! absolute difference, which also works for unsigned types
23 template <typename T>
24 T abs_diff(const T& a, const T& b) {
25  return a > b ? a - b : b - a;
26 }
27 
28 //! \}
29 
30 } // namespace tlx
31 
32 #endif // !TLX_MATH_ABS_DIFF_HEADER
33 
34 /******************************************************************************/
double T
T abs_diff(const T &a, const T &b)
absolute difference, which also works for unsigned types
Definition: abs_diff.hpp:24