# stage2: ELF: avoid multiplication for ideal capacity · gitcafe/zig

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

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

Visibility: public

Requested revision: d5d0619aacccd5e3b933b3196fba5ab6f8f9da47

Requested commit: d5d0619aacccd5e3b933b3196fba5ab6f8f9da47

Commit: d5d0619aacccd5e3b933b3196fba5ab6f8f9da47

Tree: c6705b09ed101a0fb362f1a646b1a44b9aac3d30

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: ELF: avoid multiplication for ideal capacity

ideal capacity is now determined by e.g.
x += x / f
rather than
x = x * b / a

This turns a multiplication into an addition, making it less likely to
overflow the integer. This commit also introduces padToIdeal() which
does saturating arithmetic so that no overflow is possible when
calculating ideal capacity.

closes #7830

```

## Parents

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

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