I am pretty new in C and doesn't have a good understanding of the different data types I can use.
I have an array (foo
) of half a million doubles bounded between 0 (exclusive) and 1 (inclusive), where about one third of the values are at the order of 0.01
. I am trying to calculate the geometric mean of this array.
I am doing something like
double prod = 1;
for (int i = 0; i < arraylength; i++) prod *= foo[i];
double mean = pow(prod, 1.0/arraylength);
The issue is that prod
"should become" really tiny, maybe something at the order of $10^{-10^{6}}$.
How can I solve this problem and calculate the geometric mean of foo
?