MULDIV(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸ’… MULDIV(3) β€” muldiv, umuldiv: high-precision multiplication and division πŸ’…

okay bestie, welcome to the Library Functions Manual page for MULDIV(3) πŸ’– this one’s a tiny little API with big β€œmath but make it safe” energy, and we’re obsessed.

✨ NAME ✨

muldiv, umuldiv β€” high-precision multiplication and division πŸŽ€

πŸ¦‹ SYNOPSIS πŸ¦‹

#include <u.h>
#include <libc.h>

long  muldiv(long a, long b, long c)

ulong umuldiv(ulong a, ulong b, ulong c)

🌸 DESCRIPTION 🌸

so muldiv returns a*b/c, and it uses a vlong to hold the intermediate result β€” yes, it’s giving β€œwe do the messy part somewhere roomier” πŸ’…βœ¨

umuldiv is the exact same idea but for unsigned integers. these two are here so you can scale integer values without worrying about overflowing the intermediate result. iconic behavior, honestly 🫢

⚠️ real talk, bestie: on some architectures, these routines can generate a trap if the final result does not fit in a long or ulong; on others they will silently truncate. so like… know ur architecture, okay? πŸ˜­πŸ’€

that’s the whole MULDIV(3) page β€” the footer just signs it MULDIV(3), so here’s ur cute little sign-off: stay precise, stay unsigned when u need to, and catch u in the next manpage πŸŒˆπŸ’–βœ¨