195b7b453SJohn Marino /* MIN, MAX macros. 2*09d4459fSDaniel Fojt Copyright (C) 1995, 1998, 2001, 2003, 2005, 2009-2020 Free Software 395b7b453SJohn Marino Foundation, Inc. 495b7b453SJohn Marino 595b7b453SJohn Marino This program is free software; you can redistribute it and/or modify 695b7b453SJohn Marino it under the terms of the GNU General Public License as published by 795b7b453SJohn Marino the Free Software Foundation; either version 3, or (at your option) 895b7b453SJohn Marino any later version. 995b7b453SJohn Marino 1095b7b453SJohn Marino This program is distributed in the hope that it will be useful, 1195b7b453SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 1295b7b453SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1395b7b453SJohn Marino GNU General Public License for more details. 1495b7b453SJohn Marino 1595b7b453SJohn Marino You should have received a copy of the GNU General Public License 16*09d4459fSDaniel Fojt along with this program; if not, see <https://www.gnu.org/licenses/>. */ 1795b7b453SJohn Marino 1895b7b453SJohn Marino #ifndef _MINMAX_H 1995b7b453SJohn Marino #define _MINMAX_H 2095b7b453SJohn Marino 2195b7b453SJohn Marino /* Note: MIN, MAX are also defined in <sys/param.h> on some systems 2295b7b453SJohn Marino (glibc, IRIX, HP-UX, OSF/1). Therefore you might get warnings about 2395b7b453SJohn Marino MIN, MAX macro redefinitions on some systems; the workaround is to 2495b7b453SJohn Marino #include this file as the last one among the #include list. */ 2595b7b453SJohn Marino 2695b7b453SJohn Marino /* Before we define the following symbols we get the <limits.h> file 2795b7b453SJohn Marino since otherwise we get redefinitions on some systems if <limits.h> is 2895b7b453SJohn Marino included after this file. Likewise for <sys/param.h>. 2995b7b453SJohn Marino If more than one of these system headers define MIN and MAX, pick just 3095b7b453SJohn Marino one of the headers (because the definitions most likely are the same). */ 3195b7b453SJohn Marino #if HAVE_MINMAX_IN_LIMITS_H 3295b7b453SJohn Marino # include <limits.h> 3395b7b453SJohn Marino #elif HAVE_MINMAX_IN_SYS_PARAM_H 3495b7b453SJohn Marino # include <sys/param.h> 3595b7b453SJohn Marino #endif 3695b7b453SJohn Marino 3795b7b453SJohn Marino /* Note: MIN and MAX should be used with two arguments of the 3895b7b453SJohn Marino same type. They might not return the minimum and maximum of their two 3995b7b453SJohn Marino arguments, if the arguments have different types or have unusual 4095b7b453SJohn Marino floating-point values. For example, on a typical host with 32-bit 'int', 4195b7b453SJohn Marino 64-bit 'long long', and 64-bit IEEE 754 'double' types: 4295b7b453SJohn Marino 4395b7b453SJohn Marino MAX (-1, 2147483648) returns 4294967295. 4495b7b453SJohn Marino MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0. 4595b7b453SJohn Marino MAX (NaN, 0.0) returns 0.0. 4695b7b453SJohn Marino MAX (+0.0, -0.0) returns -0.0. 4795b7b453SJohn Marino 4895b7b453SJohn Marino and in each case the answer is in some sense bogus. */ 4995b7b453SJohn Marino 5095b7b453SJohn Marino /* MAX(a,b) returns the maximum of A and B. */ 5195b7b453SJohn Marino #ifndef MAX 5295b7b453SJohn Marino # define MAX(a,b) ((a) > (b) ? (a) : (b)) 5395b7b453SJohn Marino #endif 5495b7b453SJohn Marino 5595b7b453SJohn Marino /* MIN(a,b) returns the minimum of A and B. */ 5695b7b453SJohn Marino #ifndef MIN 5795b7b453SJohn Marino # define MIN(a,b) ((a) < (b) ? (a) : (b)) 5895b7b453SJohn Marino #endif 5995b7b453SJohn Marino 6095b7b453SJohn Marino #endif /* _MINMAX_H */ 61