fixed_power(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

okay so this is the fixed_power(9) page from the Kernel API Manual, and it's all about computing x^n in O(log n) time. slay ✨

✨ NAME ✨

fixed_power β€” compute: x^n, in O(log n) time πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

u64 fixed_power (u64 x , unsigned int frac_bits , unsigned int n );

πŸŽ€ ARGUMENTS πŸŽ€

  • x β€” base of the power πŸ”₯
  • frac_bits β€” fractional bits of x πŸŽ€
  • n β€” power to raise x to. ✨

πŸ’œ DESCRIPTION πŸ’œ

okay bestie, here's the vibe: it exploits the relation between the definition of the natural power function:

x^n := x*x*...*x

(x multiplied by itself for n times), and the binary encoding of numbers used by computers:

n :=  n_i * 2^i

where: n_i \lem {0, 1}, the binary vector representing n, we find:

x^n := x^( n_i * 2^i) := Prod x^(n_i * 2^i)

which is of course trivially computable in O(log_2 n), the length of our binary vector. no cap 🫢

(see: kernel/sched/loadavg.c)

🌈 SEE ALSO 🌈

  • Kernel file ./drivers/md/dm-ps-historical-service-time.c πŸ¦‹

πŸŽ€ cute sign-off: source/version is ./drivers/md, date is October 2026, and this page is fixed_power(9) β€” bye bestie, love u! πŸ’–

πŸ“¦ where this page comes from