mul_u64_add_u64_div_u64(9)
π NAME π
mul_u64_add_u64_div_u64 β unsigned 64bit multiply, add, and divide. bestie it does exactly what it says on the tin, no cap π«Ά
it's a kernel API manual entry, so you already know this is math64.h girlie territory β¨
β¨ SYNOPSIS β¨
u64 mul_u64_add_u64_div_u64 (u64 a , u64 b , u64 c , u64 d );
π ARGUMENTS π
aβ first unsigned 64bit multiplicand. one half of the main character duo πbβ second unsigned 64bit multiplicand. the other half, they ate fr π₯cβ unsigned 64bit addend. the little sprinkle on top after the multiply πΈdβ unsigned 64bit divisor. the one doing the dividing, lowkey carrying the whole operation π
π¦ DESCRIPTION π¦
okay so picture this: you multiply two 64bit values together to generate a 128bit product, then you add a third value, and then you divide by a fourth. that's the whole vibe, it's giving math chain-reaction energy π«
the Generic code divides by 0 if d is zero and returns ~0 on overflow. yes really, that's the documented behaviour, not me being dramatic π
Architecture specific code may trap on zero or overflow β so different arches can be like "nope" and trap instead. it's giving "depends on your arch bestie, check before you ship" π
π RETURN π
(a * b + c) / d
literally just the formula, periodt β¨
π SEE ALSO π
Kernel file ./include/linux/math64.h, plus the whole math64 friend group:
div_u64_rem(9)div_s64_rem(9)div64_u64_rem(9)div64_s64_rem(9)div64_u64(9)div64_s64(9)div_u64(9)div_s64(9)mul_u64_u64_div_u64(9)mul_u64_u64_div_u64_roundup(9)DIV64_U64_ROUND_UP(9)DIV_U64_ROUND_UP(9)DIV64_U64_ROUND_CLOSEST(9)DIV_U64_ROUND_CLOSEST(9)DIV_S64_ROUND_CLOSEST(9)roundup_u64(9)
iykyk: this page lives in./include/linux, dated October 2026, and it's filed under the Kernel API Manual βmul_u64_add_u64_div_u64(9)forever and always π ok that's the whole page bestie, go forth and multiply (then add, then divide) π§π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms