MAX(3)
πΈ MAX(3) β Library Functions Manual π
okay bestie, welcome to MAX(3) from the Library Functions Manual β¨ this is a lil page about two macros that literally just pick a winner between two values, and yeah it's short but it has lore and some genuinely cursed footnotes, so stay with me π«Ά
π NAME π
MAX, MIN β get the maximum or the minimum of two values. that's it. that's the whole job. iconic honestly π
π LIBRARY π
Standard C library β that's libc, and you link it with -lc. the basics, the blueprint, the mother of all libraries π
β¨ SYNOPSIS β¨
#include <sys/param.h>
MAX(a, b);
MIN(a, b);
note the header bestie. it's<sys/param.h>, not<stdlib.h>, not<math.h>.sys/param.h. write it down. there WILL be a quiz π
π¦ DESCRIPTION π¦
these macros return the maximum or the minimum of a and b. like, MAX gives you whichever one is bigger, MIN gives you whichever one is smaller. slay, no cap, that's genuinely it π
π RETURN VALUE π
they return the value of one of their arguments π₯° which sounds simple but lowkey read the BUGS section because that "one of their arguments" might get converted to a different type on the way out. yes really. it's giving chaos π
π ERRORS π
these macros may raise the "invalid" floating-point exception when any of the arguments is NaN. so if you're feeding them NaN, don't act surprised when things get dramatic β
π§ STANDARDS π§
GNU, BSD. two whole standards said "yes we support this" and honestly? respect πΈ
π NOTES π
- if either of the arguments is a floating-point type, you might prefer to use
fmax(3)orfmin(3)instead β those two can actually handleNaNlike grownups π - the arguments may be evaluated more than once, or not at all. read that again. the macro is not a function, bestie, it's a sneaky little text substitution and it does NOT play by function rules π³
- some UNIX systems might provide these macros in a different header, or not at all. so like... vibe check your platform first π«Ά
π BUGS π
okay this is the part where it gets real. due to the usual arithmetic conversions, the result of these macros may be very different from either of the arguments. yes, the output can be something that is neither of the two things you put in. that is not a vibe, that is a jumpscare π₯
to avoid this: ensure that both arguments have the same type. same type. both of them. periodt π
π EXAMPLES π
here's the full working example, copied exactly, character for character, because we do NOT mess with code in this house:
#include <stdio.h>
#include <stdlib.h>
#include <sys/param.h>
int
main(int argc, char *argv[])
{
int a, b, x;
if (argc != 3) {
fprintf(stderr, "Usage: %s <num> <num>\n", argv[0]);
exit(EXIT_FAILURE);
}
a = atoi(argv[1]);
b = atoi(argv[2]);
x = MAX(a, b);
printf("MAX(%d, %d) is %d\n", a, b, x);
exit(EXIT_SUCCESS);
}
give it two numbers, it tells you which one ate. main character energy fr fr β
π SEE ALSO π
(the float-safe besties. go say hi π¦)
and that's the whole page, my love π this was MAX(3) from Linux man-pages 6.20, dated 2025-05-17. go forth and compare your numbers responsibly, and remember: same types, or it's over for you πΈβ¨π«Ά
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms