ioctl_tty.2: srcfix
[man-pages.git] / man3 / MAX.3
blob38d019a2d54a9e2ab23e690ef9af4d30e982f0a5
1 .\" Copyright (C) 2021 Alejandro Colomar <alx.manpages@gmail.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH MAX 3 2020-11-01 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 MAX, MIN \- maximum or minimum of two values
28 .SH SYNOPSIS
29 .nf
30 .B #include <sys/param.h>
31 .PP
32 .BI MAX( a ", " b );
33 .BI MIN( a ", " b );
34 .fi
35 .SH DESCRIPTION
36 These macros return the maximum or minimum of
37 .I a
38 and
39 .IR b .
40 .SH RETURN VALUE
41 These macros return the value of one of their arguments,
42 possibly converted to a different type (see BUGS).
43 .SH ERRORS
44 These macros may raise the "invalid" floating-point exception
45 when any of the arguments is NaN.
46 .SH CONFORMING TO
47 These nonstandard macros are present in glibc and the BSDs.
48 .SH NOTES
49 If either of the arguments is of a floating-point type,
50 you might prefer to use
51 .BR fmax (3)
53 .BR fmin (3),
54 which can handle NaN.
55 .PP
56 The arguments may be evaluated more than once, or not at all.
57 .PP
58 Some UNIX systems might provide these macros in a different header,
59 or not at all.
60 .SH BUGS
61 Due to the usual arithmetic conversions,
62 the result of these macros may be very different from either of the arguments.
63 To avoid this, ensure that both arguments have the same type.
64 .SH EXAMPLES
65 .EX
66 #include <stdio.h>
67 #include <stdlib.h>
68 #include <sys/param.h>
70 int
71 main(int argc, char *argv[])
73     int a, b, x;
75     if (argc != 3) {
76         fprintf(stderr, "Usage: %s <num> <num>\en", argv[0]);
77         exit(EXIT_FAILURE);
78     }
80     a = atoi(argv[1]);
81     b = atoi(argv[2]);
82     x = MAX(a, b);
83     printf("MAX(%d, %d) is %d\en", a, b, x);
85     exit(EXIT_SUCCESS);
87 .EE
88 .SH SEE ALSO
89 .BR fmax (3),
90 .BR fmin (3)