blitz Version 1.0.2
Loading...
Searching...
No Matches
minmax.h
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 * blitz/minmax.h Declaration of min and max functions
4 *
5 * $Id$
6 *
7 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
8 *
9 * This file is a part of Blitz.
10 *
11 * Blitz is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation, either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * Blitz is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * Suggestions: blitz-devel@lists.sourceforge.net
25 * Bugs: blitz-support@lists.sourceforge.net
26 *
27 * For more information, please see the Blitz++ Home Page:
28 * https://sourceforge.net/projects/blitz/
29 *
30 ***************************************************************************/
31
32#ifndef BZ_MINMAX_H
33#define BZ_MINMAX_H
34
35#include <blitz/promote.h>
36
37namespace blitz {
38
39/*
40 * These functions are in their own namespace (blitz::minmax) to avoid
41 * conflicts with the array reduction operations min and max.
42 */
43
44namespace extrema {
45
46template<typename T1, typename T2>
47BZ_PROMOTE(T1,T2) (min)(const T1& a, const T2& b)
48{
49 typedef BZ_PROMOTE(T1,T2) T_promote;
50
51 if (a <= b)
52 return T_promote(a);
53 else
54 return T_promote(b);
55}
56
57template<typename T1, typename T2>
58BZ_PROMOTE(T1,T2) (max)(const T1& a, const T2& b)
59{
60 typedef BZ_PROMOTE(T1,T2) T_promote;
61
62 if (a >= b)
63 return T_promote(a);
64 else
65 return T_promote(b);
66}
67
68}
69
70}
71
72#endif
else return T_promote(b)
BZ_PROMOTE(T1, T2)(min)(const T1 &a
const T2 & b
Definition minmax.h:48
Definition array-impl.h:66
N_length & a
Definition tvecglobs.h:47