fixed_power_int(9)
π 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 ofx. 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 raisingxto. the exponent. the moment.
π₯ DESCRIPTION π₯
okay so here's the slay. this function exploits the relationship between two things:
- the definition of the natural power function,
x^n := x*x*...*xβ that is,xmultiplied by itself forntimes, the classic, the original, the "i could do this with a for loop" method, and - the binary encoding of numbers that computers actually use,
n := n_i * 2^i, wheren_i \lem {0, 1}is the binary vector representingn.
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 π
- Kernel file
./kernel/sched/loadavg.c get_avenrun(9)
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
- 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