11

Avoiding a conversion over to floating point is necessary.

2 Answers2

13

rust stable v1.61.0 branch: ceil(a/b) is (a + b - 1) / b if you know that that addition won't overflow.

Nightly: https://doc.rust-lang.org/std/primitive.i32.html#method.div_ceil

2

You can use the divrem crate, concretely div_ceil:

Netwave
  • 40,134
  • 6
  • 50
  • 93