It was converting *any* number to an i32 index, which obviously is not correct for negative ints, doubles, infinity and nan. Fixes #3712.