Skip to content

Conversation

@nnethercote
Copy link
Contributor

Several places in the tutorial need to do a division that rounds up, for chunking operations. They use a form like n / k + (n % k > 0).

I'm used to seeing this kind of division done with (n + (k - 1)) / k. This is probably preferred because it avoids the % operation, which is typically expensive.

But Rust has a builtin for this: div_ceil. Even better.

Several places in the tutorial need to do a division that rounds up, for
chunking operations. They use a form like `n / k + (n % k > 0)`.

I'm used to seeing this kind of division done with `(n + (k - 1)) / k`.
This is probably preferred because it avoids the `%` operation, which is
typically expensive.

But Rust has a builtin for this: `div_ceil`. Even better.
@sotrh sotrh merged commit da2da03 into sotrh:master Oct 3, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants