Although this is much more complicated it does not seem to impact performance that much even when looking only at values in which the previous casting to i32 was correct.