| 1 |
.\" Copyright, the authors of the Linux man-pages project |
| 2 |
.\" |
| 3 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 4 |
.\" |
| 5 |
.TH MAX 3 2025-05-17 "Linux man-pages 6.18" |
| 6 |
.SH NAME |
| 7 |
MAX, MIN \- maximum or minimum of two values |
| 8 |
.SH LIBRARY |
| 9 |
Standard C library |
| 10 |
.RI ( libc ,\~ \-lc ) |
| 11 |
.SH SYNOPSIS |
| 12 |
.nf |
| 13 |
.B #include <sys/param.h> |
| 14 |
.P |
| 15 |
.BI MAX( a ", " b ); |
| 16 |
.BI MIN( a ", " b ); |
| 17 |
.fi |
| 18 |
.SH DESCRIPTION |
| 19 |
These macros return the maximum or minimum of |
| 20 |
.I a |
| 21 |
and |
| 22 |
.IR b . |
| 23 |
.SH RETURN VALUE |
| 24 |
These macros return the value of one of their arguments, |
| 25 |
possibly converted to a different type (see BUGS). |
| 26 |
.SH ERRORS |
| 27 |
These macros may raise the "invalid" floating-point exception |
| 28 |
when any of the arguments is NaN. |
| 29 |
.SH STANDARDS |
| 30 |
GNU, BSD. |
| 31 |
.SH NOTES |
| 32 |
If either of the arguments is of a floating-point type, |
| 33 |
you might prefer to use |
| 34 |
.BR fmax (3) |
| 35 |
or |
| 36 |
.BR fmin (3), |
| 37 |
which can handle NaN. |
| 38 |
.P |
| 39 |
The arguments may be evaluated more than once, or not at all. |
| 40 |
.P |
| 41 |
Some UNIX systems might provide these macros in a different header, |
| 42 |
or not at all. |
| 43 |
.SH BUGS |
| 44 |
Due to the usual arithmetic conversions, |
| 45 |
the result of these macros may be very different from either of the arguments. |
| 46 |
To avoid this, ensure that both arguments have the same type. |
| 47 |
.SH EXAMPLES |
| 48 |
.\" SRC BEGIN (MAX.c) |
| 49 |
.EX |
| 50 |
#include <stdio.h> |
| 51 |
#include <stdlib.h> |
| 52 |
#include <sys/param.h> |
| 53 |
\& |
| 54 |
int |
| 55 |
main(int argc, char *argv[]) |
| 56 |
{ |
| 57 |
int a, b, x; |
| 58 |
\& |
| 59 |
if (argc != 3) { |
| 60 |
fprintf(stderr, "Usage: %s <num> <num>\[rs]n", argv[0]); |
| 61 |
exit(EXIT_FAILURE); |
| 62 |
} |
| 63 |
\& |
| 64 |
a = atoi(argv[1]); |
| 65 |
b = atoi(argv[2]); |
| 66 |
x = MAX(a, b); |
| 67 |
printf("MAX(%d, %d) is %d\[rs]n", a, b, x); |
| 68 |
\& |
| 69 |
exit(EXIT_SUCCESS); |
| 70 |
} |
| 71 |
.EE |
| 72 |
.\" SRC END |
| 73 |
.SH SEE ALSO |
| 74 |
.BR fmax (3), |
| 75 |
.BR fmin (3) |