1 #if !defined  HAVE_MINMAXMED23_H__
2 #define       HAVE_MINMAXMED23_H__
3 // This file is part of the FXT library.
4 // Copyright (C) 2010, 2012 Joerg Arndt
5 // License: GNU General Public License version 3 or later,
6 // see the file COPYING.txt in the main directory.
7 
8 
9 #include "fxttypes.h"
10 
11 //: minimum and maximum of 2 or 3 elements
12 //: minimum, maximum and median of 3 elements
13 
14 
15 template <typename Type>
min2(const Type & x,const Type & y)16 static inline Type  min2(const Type &x, const Type &y)
17 // Return minimum of the input values
18 { return  x<y ? x : y; }
19 
20 template <typename Type>
max2(const Type & x,const Type & y)21 static inline Type  max2(const Type &x, const Type &y)
22 // Return maximum of the input values
23 { return  x>y ? x : y; }
24 
25 
26 
27 template <typename Type>
min3(const Type & x,const Type & y,const Type & z)28 static inline Type  min3(const Type &x, const Type &y, const Type &z)
29 // Return minimum of the input values
30 { return  min2( min2(x, y), z ); }
31 
32 template <typename Type>
max3(const Type & x,const Type & y,const Type & z)33 static inline Type  max3(const Type &x, const Type &y, const Type &z)
34 // Return maximum of the input values
35 { return  max2( max2(x, y), z ); }
36 
37 template <typename Type>
median3(const Type & x,const Type & y,const Type & z)38 static inline Type  median3(const Type &x, const Type &y, const Type &z)
39 // Return median of the input values
40 { return  x<y ? (y<z ? y : (x<z ? z : x)) : (z<y ? y : (z<x ? z : x)); }
41 
42 
43 #endif  // !defined HAVE_MINMAXMED23_H__
44