In a language like C, I'd do int ans = ceil(1.0*x/y) without much thought, but here with all the as casting going no, I'm wondering if there is a better way.

You would have to treat unmatched signs differently. It's best to put this into a helper extension-trait method so that you can invoke x.div_ceil(y). You could also ask the num crate maintainers to add it to their Integer trait.

Though, using the num crate's Integer trait, you could use div_floor and use the formula above: (x-1).div_floor(y) + 1. Actually, comes to think of it, -(-x).div_floor(y) is even shorter (since floor is the opposite of ceil).

Note that the f32 approach will produce incorrect (approximated) results for large enough numbers. f64 should be precise for all 32-bit integers, but if isize is 64-bit then there’s no way to do it fully correctly with floating point.