Home | History | Annotate | Line # | Download | only in lib
      1  1.1  christos /* MIN, MAX macros.
      2  1.1  christos    Copyright (C) 1995, 1998, 2001, 2003, 2005 Free Software Foundation, Inc.
      3  1.1  christos 
      4  1.1  christos    This program is free software; you can redistribute it and/or modify
      5  1.1  christos    it under the terms of the GNU General Public License as published by
      6  1.1  christos    the Free Software Foundation; either version 2, or (at your option)
      7  1.1  christos    any later version.
      8  1.1  christos 
      9  1.1  christos    This program is distributed in the hope that it will be useful,
     10  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  1.1  christos    GNU General Public License for more details.
     13  1.1  christos 
     14  1.1  christos    You should have received a copy of the GNU General Public License
     15  1.1  christos    along with this program; if not, write to the Free Software Foundation,
     16  1.1  christos    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
     17  1.1  christos 
     18  1.1  christos #ifndef _MINMAX_H
     19  1.1  christos #define _MINMAX_H
     20  1.1  christos 
     21  1.1  christos /* Note: MIN, MAX are also defined in <sys/param.h> on some systems
     22  1.1  christos    (glibc, IRIX, HP-UX, OSF/1).  Therefore you might get warnings about
     23  1.1  christos    MIN, MAX macro redefinitions on some systems; the workaround is to
     24  1.1  christos    #include this file as the last one among the #include list.  */
     25  1.1  christos 
     26  1.1  christos /* Before we define the following symbols we get the <limits.h> file
     27  1.1  christos    since otherwise we get redefinitions on some systems if <limits.h> is
     28  1.1  christos    included after this file.  Likewise for <sys/param.h>.
     29  1.1  christos    If more than one of these system headers define MIN and MAX, pick just
     30  1.1  christos    one of the headers (because the definitions most likely are the same).  */
     31  1.1  christos #if HAVE_MINMAX_IN_LIMITS_H
     32  1.1  christos # include <limits.h>
     33  1.1  christos #elif HAVE_MINMAX_IN_SYS_PARAM_H
     34  1.1  christos # include <sys/param.h>
     35  1.1  christos #endif
     36  1.1  christos 
     37  1.1  christos /* Note: MIN and MAX should be used with two arguments of the
     38  1.1  christos    same type.  They might not return the minimum and maximum of their two
     39  1.1  christos    arguments, if the arguments have different types or have unusual
     40  1.1  christos    floating-point values.  For example, on a typical host with 32-bit 'int',
     41  1.1  christos    64-bit 'long long', and 64-bit IEEE 754 'double' types:
     42  1.1  christos 
     43  1.1  christos      MAX (-1, 2147483648) returns 4294967295.
     44  1.1  christos      MAX (9007199254740992.0, 9007199254740993) returns 9007199254740992.0.
     45  1.1  christos      MAX (NaN, 0.0) returns 0.0.
     46  1.1  christos      MAX (+0.0, -0.0) returns -0.0.
     47  1.1  christos 
     48  1.1  christos    and in each case the answer is in some sense bogus.  */
     49  1.1  christos 
     50  1.1  christos /* MAX(a,b) returns the maximum of A and B.  */
     51  1.1  christos #ifndef MAX
     52  1.1  christos # define MAX(a,b) ((a) > (b) ? (a) : (b))
     53  1.1  christos #endif
     54  1.1  christos 
     55  1.1  christos /* MIN(a,b) returns the minimum of A and B.  */
     56  1.1  christos #ifndef MIN
     57  1.1  christos # define MIN(a,b) ((a) < (b) ? (a) : (b))
     58  1.1  christos #endif
     59  1.1  christos 
     60  1.1  christos #endif /* _MINMAX_H */
     61