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) or fmin(3) instead β€” those two can actually handle NaN like 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