root/lib/minmax.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */