]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/MAX.3
c73a32f7d34d67945c4e685a85e4458fb8f6bef4
[thirdparty/man-pages.git] / man3 / MAX.3
1 .\" Copyright (C) 2021 Alejandro Colomar <alx.manpages@gmail.com>
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH MAX 3 2020-11-01 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
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 .PP
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 These nonstandard macros are present in glibc and the BSDs.
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 .PP
39 The arguments may be evaluated more than once, or not at all.
40 .PP
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 .EX
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <sys/param.h>
52
53 int
54 main(int argc, char *argv[])
55 {
56 int a, b, x;
57
58 if (argc != 3) {
59 fprintf(stderr, "Usage: %s <num> <num>\en", argv[0]);
60 exit(EXIT_FAILURE);
61 }
62
63 a = atoi(argv[1]);
64 b = atoi(argv[2]);
65 x = MAX(a, b);
66 printf("MAX(%d, %d) is %d\en", a, b, x);
67
68 exit(EXIT_SUCCESS);
69 }
70 .EE
71 .SH SEE ALSO
72 .BR fmax (3),
73 .BR fmin (3)