minmax.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  * blitz/minmax.h  Declaration of min and max functions
00003  *
00004  * $Id: minmax.h,v 1.4 2003/12/11 03:44:22 julianc Exp $
00005  *
00006  * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * Suggestions:          blitz-dev@oonumerics.org
00019  * Bugs:                 blitz-bugs@oonumerics.org
00020  *
00021  * For more information, please see the Blitz++ Home Page:
00022  *    http://oonumerics.org/blitz/
00023  *
00024  ***************************************************************************/
00025 
00026 #ifndef BZ_MINMAX_H
00027 #define BZ_MINMAX_H
00028 
00029 #include <blitz/promote.h>
00030 
00031 BZ_NAMESPACE(blitz)
00032 
00033 /*
00034  * These functions are in their own namespace (blitz::minmax) to avoid
00035  * conflicts with the array reduction operations min and max.
00036  */
00037 
00038 BZ_NAMESPACE(minmax)
00039 
00040 template<typename T1, typename T2>
00041 BZ_PROMOTE(T1,T2) min(const T1& a, const T2& b)
00042 {
00043     typedef BZ_PROMOTE(T1,T2) T_promote;
00044 
00045     if (a <= b)
00046         return T_promote(a);
00047     else
00048         return T_promote(b);
00049 }
00050 
00051 template<typename T1, typename T2>
00052 BZ_PROMOTE(T1,T2) max(const T1& a, const T2& b)
00053 {
00054     typedef BZ_PROMOTE(T1,T2) T_promote;
00055 
00056     if (a >= b)
00057         return T_promote(a);
00058     else
00059         return T_promote(b);
00060 }
00061 
00062 BZ_NAMESPACE_END
00063 
00064 BZ_NAMESPACE_END
00065 
00066 #endif

Generated on Mon Oct 22 10:04:51 2007 for blitz by  doxygen 1.3.9.1