Are we so sure that the index being used is taking into account for the fact that dynamic arrays start at 0 and end at 1 less than the size ?
Maybe showing some more code here may help, but I think using Low and High of the Array may help avoid that.
Also, is it possible the function is failing to trim off the floating point errors ?
EDIT:
Wanted to add, is the size of the array being set?