clamp_t(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… clamp_t(9) β€” the group chat version

okay so bestie, this is a page straight out of the Kernel API Manual (yes, the clamp_t(9) one β€” you found it, proud of you 🫢), and I'm gonna walk you through it like we're texting at 2am.


✨ NAME ✨

clamp_t β€” return a value clamped to a given range using a given type πŸŽ€

like... it clamps. with a type. that's the whole vibe.


🌸 SYNOPSIS 🌸

clamp_t (type , val , lo , hi );

four little arguments, one iconic macro. no cap. ⭐


πŸ¦‹ ARGUMENTS πŸ¦‹

  • type β€” the type of variable to use πŸ’œ like, what flavour of number are we working with here
  • val β€” current value πŸ”₯ the one that needs to get put in its place
  • lo β€” minimum allowable value πŸ“ the floor, literally
  • hi β€” maximum allowable value πŸ‘‘ the ceiling, the limit, the final boss

πŸ’€ DESCRIPTION πŸ’€

So here's the tea: this macro does no typechecking 😭 like zero, none, it does not check your vibes at the door. It just uses temporary variables of type type to make all the comparisons. That's it. That's the whole description. It's giving "small but mighty" energy. πŸ™ˆ

ngl this is the part where I remind you: no typechecking means no typechecking. fr fr. the macro trusts you completely and that's a lot of pressure. πŸ’…

πŸ”₯ SEE ALSO πŸ”₯

The kernel file ./include/linux/minmax.h (yes, that's where the family lives 🧚) and honestly the whole minmax friend group ate:

min(9), max(9), umin(9), umax(9), min3(9), max3(9), min_t(9), max_t(9), min_not_zero(9), clamp(9), clamp_val(9), min_array(9), max_array(9), in_range(9), swap(9)

collect them all bestie, they're all in there πŸ’–βœ¨


mwah, that's the page! 🌈 This little love letter comes to you from ./include/linux, dated October 2026 β€” clamp responsibly, and remember: the typechecking was inside you all along (jk it wasn't, please be careful πŸ’€πŸ’…).

πŸ“¦ where this page comes from