mirror of
https://github.com/ziglang/zig.git
synced 2025-12-07 14:53:08 +00:00
Implemented following Knuth's "Evaluation of Powers" chapter in TAOCP, some extra complexity is needed to make sure there's no aliasing and avoid allocating too many limbs. A brief example to illustrate why the last point is important: consider 10^123, since 10 is well within the limits of a single limb we can safely say that the result will surely fit in: ⌈log2(10)⌉ bit * 123 = 492 bits = 7 limbs A naive calculation using only the number of limbs yields: 1 limb * 123 = 123 limbs The space savings are noticeable.