.\" Copyright (C) 2021 Alejandro Colomar .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .TH MAX 3 2020-11-01 "Linux" "Linux Programmer's Manual" .SH NAME MAX, MIN \- maximum or minimum of two values .SH SYNOPSIS .nf .B #include .PP .BI MAX( a ", " b ); .BI MIN( a ", " b ); .fi .SH DESCRIPTION These macros return the maximum or minimum of .I a and .IR b . .SH RETURN VALUE These macros return the value of one of their arguments, possibly converted to a different type (see BUGS). .SH ERRORS These macros may raise the "invalid" floating-point exception when any of the arguments is NaN. .SH CONFORMING TO These nonstandard macros are present in glibc and the BSDs. .SH NOTES If either of the arguments is of a floating-point type, you might prefer to use .BR fmax (3) or .BR fmin (3), which can handle NaN. .PP The arguments may be evaluated more than once, or not at all. .PP Some UNIX systems might provide these macros in a different header, or not at all. .SH BUGS Due to the usual arithmetic conversions, the result of these macros may be very different from either of the arguments. To avoid this, ensure that both arguments have the same type. .SH EXAMPLES .EX #include #include #include int main(int argc, char *argv[]) { int a, b, x; if (argc != 3) { fprintf(stderr, "Usage: %s \en", argv[0]); exit(EXIT_FAILURE); } a = atoi(argv[1]); b = atoi(argv[2]); x = MAX(a, b); printf("MAX(%d, %d) is %d\en", a, b, x); exit(EXIT_SUCCESS); } .EE .SH SEE ALSO .BR fmax (3), .BR fmin (3)