Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
utility.functions.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file utility/utility.functions.hh
11 /// @brief Numeric functions (to avoid dependency on numeric package)
12 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
13 
14 
15 #ifndef INCLUDED_utility_utility_functions_hh
16 #define INCLUDED_utility_utility_functions_hh
17 
18 
19 // C++ headers
20 #include <algorithm>
21 #include <utility/assert.hh>
22 #include <cmath>
23 #include <limits>
24 
25 
26 namespace utility {
27 
28 
29 // min functions: Specializations for built-in types pass by value for speed
30 
31 
32 /// @brief min( short int, short int )
33 inline
34 short int
35 min( short int const a, short int const b )
36 {
37  return ( a < b ? a : b );
38 }
39 
40 
41 /// @brief min( int, int )
42 inline
43 int
44 min( int const a, int const b )
45 {
46  return ( a < b ? a : b );
47 }
48 
49 
50 /// @brief min( long int, long int )
51 inline
52 long int
53 min( long int const a, long int const b )
54 {
55  return ( a < b ? a : b );
56 }
57 
58 
59 /// @brief min( unsigned short int, unsigned short int )
60 inline
61 unsigned short int
62 min( unsigned short int const a, unsigned short int const b )
63 {
64  return ( a < b ? a : b );
65 }
66 
67 
68 /// @brief min( unsigned int, unsigned int )
69 inline
70 unsigned int
71 min( unsigned int const a, unsigned int const b )
72 {
73  return ( a < b ? a : b );
74 }
75 
76 
77 /// @brief min( unsigned long int, unsigned long int )
78 inline
79 unsigned long int
80 min( unsigned long int const a, unsigned long int const b )
81 {
82  return ( a < b ? a : b );
83 }
84 
85 
86 /// @brief min( float, float )
87 inline
88 float
89 min( float const a, float const b )
90 {
91  return ( a < b ? a : b );
92 }
93 
94 
95 /// @brief min( double, double )
96 inline
97 double
98 min( double const a, double const b )
99 {
100  return ( a < b ? a : b );
101 }
102 
103 
104 /// @brief min( long double, long double )
105 inline
106 long double
107 min( long double const a, long double const b )
108 {
109  return ( a < b ? a : b );
110 }
111 
112 
113 /// @brief Use std::min for 2 arguments
114 using std::min;
115 
116 
117 /// @brief min( a, b, c )
118 template< typename T >
119 inline
120 T const &
121 min( T const & a, T const & b, T const & c )
122 {
123  return ( a < b ? ( a < c ? a : c ) : ( b < c ? b : c ) );
124 }
125 
126 
127 /// @brief min( a, b, c, d )
128 template< typename T >
129 inline
130 T const &
131 min( T const & a, T const & b, T const & c, T const & d )
132 {
133  return std::min( std::min( a, b ), std::min( c, d ) );
134 }
135 
136 
137 /// @brief min( a, b, c, d, e )
138 template< typename T >
139 inline
140 T const &
141 min( T const & a, T const & b, T const & c, T const & d, T const & e )
142 {
143  return min( std::min( a, b ), std::min( c, d ), e );
144 }
145 
146 
147 /// @brief min( a, b, c, d, e, f )
148 template< typename T >
149 inline
150 T const &
151 min( T const & a, T const & b, T const & c, T const & d, T const & e, T const & f )
152 {
153  return min( std::min( a, b ), std::min( c, d ), std::min( e, f ) );
154 }
155 
156 
157 // max functions: Specializations for built-in types pass by value for speed
158 
159 
160 /// @brief max( short int, short int )
161 inline
162 short int
163 max( short int const a, short int const b )
164 {
165  return ( a < b ? b : a );
166 }
167 
168 
169 /// @brief max( int, int )
170 inline
171 int
172 max( int const a, int const b )
173 {
174  return ( a < b ? b : a );
175 }
176 
177 
178 /// @brief max( long int, long int )
179 inline
180 long int
181 max( long int const a, long int const b )
182 {
183  return ( a < b ? b : a );
184 }
185 
186 
187 /// @brief max( unsigned short int, unsigned short int )
188 inline
189 unsigned short int
190 max( unsigned short int const a, unsigned short int const b )
191 {
192  return ( a < b ? b : a );
193 }
194 
195 
196 /// @brief max( unsigned int, unsigned int )
197 inline
198 unsigned int
199 max( unsigned int const a, unsigned int const b )
200 {
201  return ( a < b ? b : a );
202 }
203 
204 
205 /// @brief max( unsigned long int, unsigned long int )
206 inline
207 unsigned long int
208 max( unsigned long int const a, unsigned long int const b )
209 {
210  return ( a < b ? b : a );
211 }
212 
213 
214 /// @brief max( float, float )
215 inline
216 float
217 max( float const a, float const b )
218 {
219  return ( a < b ? b : a );
220 }
221 
222 
223 /// @brief max( double, double )
224 inline
225 double
226 max( double const a, double const b )
227 {
228  return ( a < b ? b : a );
229 }
230 
231 
232 /// @brief max( long double, long double )
233 inline
234 long double
235 max( long double const a, long double const b )
236 {
237  return ( a < b ? b : a );
238 }
239 
240 
241 /// @brief Use std::max for 2 arguments
242 using std::max;
243 
244 
245 /// @brief max( a, b, c )
246 template< typename T >
247 inline
248 T const &
249 max( T const & a, T const & b, T const & c )
250 {
251  return ( a < b ? ( b < c ? c : b ) : ( a < c ? c : a ) );
252 }
253 
254 
255 /// @brief max( a, b, c, d )
256 template< typename T >
257 inline
258 T const &
259 max( T const & a, T const & b, T const & c, T const & d )
260 {
261  return std::max( std::max( a, b ), std::max( c, d ) );
262 }
263 
264 
265 /// @brief max( a, b, c, d, e )
266 template< typename T >
267 inline
268 T const &
269 max( T const & a, T const & b, T const & c, T const & d, T const & e )
270 {
271  return max( std::max( a, b ), std::max( c, d ), e );
272 }
273 
274 
275 /// @brief max( a, b, c, d, e, f )
276 template< typename T >
277 inline
278 T const &
279 max( T const & a, T const & b, T const & c, T const & d, T const & e, T const & f )
280 {
281  return max( std::max( a, b ), std::max( c, d ), std::max( e, f ) );
282 }
283 
284 
285 } // namespace utility
286 
287 
288 #endif // INCLUDED_utility_utility_functions_HH
static T min(T x, T y)
Definition: Svm.cc:16
short int max(short int const a, short int const b)
max( short int, short int )
short int min(short int const a, short int const b)
min( short int, short int )
static T max(T x, T y)
Definition: Svm.cc:19