fixed_power(9)
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 ofxπnβ power to raisexto. β¨
π 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
- 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