The problem with this function is that iValue and iBestValue are both 32-bit integers. It's not difficult to overflow them, and to get unexpected values.
While changing these to type long would likely work, float will definitely work, which is what I chose to do.
Code omitted due to length and the simplicity of the change.
While changing these to type long would likely work, float will definitely work, which is what I chose to do.
Code omitted due to length and the simplicity of the change.