# std: Add pow\(a,b\) for big ints · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/538d485782629a358c2dd0f8e34d74813e3c9526)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 538d485782629a358c2dd0f8e34d74813e3c9526

Requested commit: 538d485782629a358c2dd0f8e34d74813e3c9526

Commit: 538d485782629a358c2dd0f8e34d74813e3c9526

Tree: d67182c6085d69a63d3f495d0c180b2b149d52c7

Author: LemonBoy

Committer: Andrew Kelley

## Message

```
std: Add pow(a,b) for big ints

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.

```

## Parents

- [2de53592a1d84a1476f662e20d7339d25d4716fe](https://git.cafe/gitcafe/zig/commit/2de53592a1d84a1476f662e20d7339d25d4716fe?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/538d485782629a358c2dd0f8e34d74813e3c9526?format=markdown)
