|Keep It Simple, Stupid|
Is this odd behavior a floating point problem?by wickedjester (Initiate)
|on Mar 23, 2012 at 16:58 UTC||Need Help??|
wickedjester has asked for the
wisdom of the Perl Monks concerning the following question:
I've got an array with 40 elements with each element having a value of '0.001'. If I add them all together and divide by 40 to get the average, I get something like:
$Avg = 0.001025
rather than 0.001, which is what it should really return.
Now, the script I'm righting is a chemical diffusion model dealing with very small numbers and this kind of inaccuracy is causing me problems. If this is a floating point issue, can anyone give me a recommendation on how to deal with this?