It’s a bit tricky because of inexact mapping from floats to integers. For example,
Float32 can represent 2^31 perfectly, whereas
ERROR: InexactError: trunc(Int32, 2.1474836e9)
It should also be possible to create similar errors when rounding certain
Int64. It’s unclear what the intention should be with such edge cases, and it’s probably unreasonable to play it safe by returning
round(Integer, Float32(x)). Some might say it’s not great to default to
round(Int, Float32(x)) because the result can then differ between 32- and 64-bit CPUs. I guess Python will use bigger integers when needed, but with a big trade-off in performance.
Only the coder knows their use case, and they are probably better off being concrete,
round(Int32, Float32(x)) when they know it will work.