I am seeing some strange behavior converting float32 to int32:
var f float32 = math.MaxInt32
fmt.Printf("%d %0.1f %d
", math.MaxInt32, f, int32(f))
prints
2147483647 2147483648.0 -2147483648
(At Go Playground: https://play.golang.org/p/SI0RtpZFkwa)
My guess is that there are a few things going on here, like general IEEE floating point imprecision and untamed automatic conversions. I would almost expect the "off by one" type of error, but why the sign conversion?
Seems like a bug, but at the very least, it's surprising. This cropped up in a larger system that started behaving strangely at the edges.
Ultimately, I just want to be able to convert float32
values to int32
in some reasonable way.