00001 /* MIN, MAX macros. 00002 Copyright (C) 1995, 1998, 2001, 2003, 2005 Free Software Foundation, Inc. 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as published by 00006 the Free Software Foundation; either version 2.1, or (at your option) 00007 any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public License 00015 along with this program; if not, write to the Free Software Foundation, 00016 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 00017 00018 #ifndef _MINMAX_H 00019 #define _MINMAX_H 00020 00021 /* Note: MIN, MAX are also defined in <sys/param.h> on some systems 00022 (glibc, IRIX, HP-UX, OSF/1). Therefore you might get warnings about 00023 MIN, MAX macro redefinitions on some systems; the workaround is to 00024 #include this file as the last one among the #include list. */ 00025 00026 /* Before we define the following symbols we get the <limits.h> file 00027 since otherwise we get redefinitions on some systems if <limits.h> is 00028 included after this file. Likewise for <sys/param.h>. 00029 If more than one of these system headers define MIN and MAX, pick just 00030 one of the headers (because the definitions most likely are the same). */ 00031 #if HAVE_MINMAX_IN_LIMITS_H 00032 # include <limits.h> 00033 #elif HAVE_MINMAX_IN_SYS_PARAM_H 00034 # include <sys/param.h> 00035 #endif 00036 00037 /* Note: MIN and MAX should be used with two arguments of the 00038 same type. They might not return the minimum and maximum of their two 00039 arguments, if the arguments have different types or have unusual 00040 floating-point values. For example, on a typical host with 32-bit 'int', 00041 64-bit 'long long', and 64-bit IEEE 754 'double' types: 00042 00043 MAX (-1, 2147483648) returns 4294967295. 00044 MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0. 00045 MAX (NaN, 0.0) returns 0.0. 00046 MAX (+0.0, -0.0) returns -0.0. 00047 00048 and in each case the answer is in some sense bogus. */ 00049 00050 /* MAX(a,b) returns the maximum of A and B. */ 00051 #ifndef MAX 00052 # define MAX(a,b) ((a) > (b) ? (a) : (b)) 00053 #endif 00054 00055 /* MIN(a,b) returns the minimum of A and B. */ 00056 #ifndef MIN 00057 # define MIN(a,b) ((a) < (b) ? (a) : (b)) 00058 #endif 00059 00060 #endif /* _MINMAX_H */