do_div(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… do_div(9)

okay so bestie, welcome to the Kernel API Manual β€” this one's a lil macro from the kernel, do_div, and she's doing two things at once because she's a multitasking icon ✨


🌸 NAME

do_div β€” returns 2 values: calculate remainder and update new dividend 🫢

like, she literally does both. no cap.


πŸŽ€ SYNOPSIS

do_div (n , base );

that's it. that's the whole vibe check. πŸ’…


πŸ¦‹ ARGUMENTS

  • n β€” a uint64_t dividend β€” and heads up, she will be updated πŸ”₯ (yes, the macro writes back into her, that's the whole point)
  • base β€” a uint32_t divisor β€” the thing you're dividing by πŸ“

✨ DESCRIPTION

Summary, and I'm quoting the manpage's own summary here because it's already giving:

uint32_t remainder = n % base;
n = n / base;

so literally: grab the remainder from n % base, then overwrite n with n / base. two-for-one. ate and left no crumbs πŸ‘‘


πŸ’œ RETURN

(uint32_t)remainder β€” the remainder, cast to uint32_t, that's your comeback value 🌈


πŸ’€ NOTE

⚠️ macro parameter n is evaluated multiple times β€” beware of side effects! 😭

fr fr, this is the important one. if you pass something with a side effect in it (like n++ or a function call), it's gonna fire off more than once and that's a situation. guard your vibes. 🫢


🧚 SEE ALSO

Kernel file ./include/asm-generic/div64.h πŸ‘‘ β€” go read the source, it's giving main character energy.


kisses bestie, this page came to you from ./include/asm-generic, dated October 2026, and it's do_div(9) β€” slay, study up, and may all your remainders be correct πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from