1MAX(3) Linux Programmer's Manual MAX(3)
2
3
4
6 MAX, MIN - maximum or minimum of two values
7
9 #include <sys/param.h>
10
11 MAX(a, b);
12 MIN(a, b);
13
15 These macros return the maximum or minimum of a and b.
16
18 These macros return the value of one of their arguments, possibly con‐
19 verted to a different type (see BUGS).
20
22 These macros may raise the "invalid" floating-point exception when any
23 of the arguments is NaN.
24
26 These nonstandard macros are present in glibc and the BSDs.
27
29 If either of the arguments is of a floating-point type, you might pre‐
30 fer to use fmax(3) or fmin(3), which can handle NaN.
31
32 The arguments may be evaluated more than once, or not at all.
33
34 Some UNIX systems might provide these macros in a different header, or
35 not at all.
36
38 Due to the usual arithmetic conversions, the result of these macros may
39 be very different from either of the arguments. To avoid this, ensure
40 that both arguments have the same type.
41
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <sys/param.h>
46
47 int
48 main(int argc, char *argv[])
49 {
50 int a, b, x;
51
52 if (argc != 3) {
53 fprintf(stderr, "Usage: %s <num> <num>\n", argv[0]);
54 exit(EXIT_FAILURE);
55 }
56
57 a = atoi(argv[1]);
58 b = atoi(argv[2]);
59 x = MAX(a, b);
60 printf("MAX(%d, %d) is %d\n", a, b, x);
61
62 exit(EXIT_SUCCESS);
63 }
64
66 fmax(3), fmin(3)
67
69 This page is part of release 5.13 of the Linux man-pages project. A
70 description of the project, information about reporting bugs, and the
71 latest version of this page, can be found at
72 https://www.kernel.org/doc/man-pages/.
73
74
75
76Linux 2020-11-01 MAX(3)