fixed_power_int(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… fixed_power_int β€” Kernel API Manual, section 9, bestie πŸ’…

okay so this is fixed_power_int(9) straight out of the Kernel API Manual, and it's genuinely one of those little functions that ate and left no crumbs. it does one thing: raises x to the power n, in O(log n) time. that's the whole vibe. iykyk. πŸŽ€


✨ NAME ✨

fixed_power_int β€” compute: x^n, in O(log n) time. literally that's it, that's the function, and it's iconic for it. πŸ’–


🌸 SYNOPSIS 🌸

unsigned long fixed_power_int (unsigned long x , unsigned int frac_bits
, unsigned int n );

copy it exactly like that, spacing and all, don't come for me, that's the manpage's formatting not mine 🫢


πŸ¦‹ ARGUMENTS πŸ¦‹

  • x β€” the base of the power. the main character of this whole operation ngl.
  • frac_bits β€” fractional bits of x. yes it's a parameter, yes the description doesn't elaborate, no i will not be inventing lore about it πŸ’€
  • n β€” the power you're raising x to. the exponent. the moment.

πŸ”₯ DESCRIPTION πŸ”₯

okay so here's the slay. this function exploits the relationship between two things:

  1. the definition of the natural power function, x^n := x*x*...*x β€” that is, x multiplied by itself for n times, the classic, the original, the "i could do this with a for loop" method, and
  2. the binary encoding of numbers that computers actually use, n := n_i * 2^i, where n_i \lem {0, 1} is the binary vector representing n.

put those two together and you find:

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

which is, in the manpage's own words, "of course trivially computable in O(log_2 n)" β€” the length of our binary vector. so instead of doing n multiplications like a peasant, you're doing logarithmically many, which is giving big brain energy fr fr. 🧚✨

ngl the original page really does say "of course trivially computable" like it's the most obvious thing in the world. and honestly? for her it is. πŸ‘‘

πŸ’œ SEE ALSO πŸ’œ

go read those if you want the full lore, bestie, i'm just the messenger 🌈


and that's the page!! πŸ’… this little beauty lives in ./kernel/sched and this version is dated October 2026, title fixed_power_int(9), in case you were wondering where it came from. k byeee, go compute some powers πŸ“πŸ¦‹πŸ’–

πŸ“¦ where this page comes from