Safe int casting utility function

Improved from the simpler version into a fully robust function which accepts and returns scalars or iterables of any type, and checks on both sides of the nearest integer (e.g., `% 1` can return 0.999999999999, which we want to catch and interpret as 1).

Also, documentation and tests!

I didn't actually insert this into the warp function here, so as to create minimal merge issues for you ;)

If you prefer a different naming convention, I'd be happy to oblige.