in reply to Is this odd behavior a floating point problem?
For reasons described in excruciating detail in the document already cited, there will be errors, but according to a quick test on my system, they are nowhere near as large as you claim:
$ perl -e '$x=0.001; $sum += $x for 1..40; printf "%.20f", $sum/40'
Looks more like a "one off" error to me (i.e. summing over one more than you divide by):
$ perl -e '$x=0.001; $sum += $x for 0..40; printf "%.20f", $sum/40'