Your formula is correct if you are calculating the average of many numbers. In this case, you can do the following:
& mu; n= 1 / n? Sigma; x i
but when adding the 101st number you will need to add x 101 to & mu; 100where & mu; 100 can be quite large compared to x 101, . , :
& mu; 101= & mu; 100 + 1/n (x 101 - & mu; 100))
, x i , x i.
,
, IEEE. ++ float:
[1,2] 2 -23 1 + n * 2 -23 n {0,..., 2 23}.
[2 j 2 j + 1] [1,2], 2 j.
To, , , :
#include <iostream>
#include <iomanip>
int main() {
float d = pow(2,-23);
std::cout << d << std::endl;
std::cout << std::setprecision(8) << d + 1 << std::endl;
std::cout << std::setprecision(8) << d + 2 << std::endl;
system("pause");
}
1.19209e-07
1.0000001
2