我的小米有小问题,我有一套从特定数据中计算平均值的代码,我从几台不同的计算机(有些有气球,有些有窗户,约32个轨道,其他64个轨道)这样做,但在我观察数据库时,某些应同等的数值略有不同。
This makes no difference for my program but I was wondering why it was this way, I was under the impression that floating point operations with the same word lenght should yield the same result (I was obviously wrong).
这是我写来的小型样本代码,用于检查:
public class Test{
public static void main(String... args){
double counter = 0, value = 1./10;
for (int i = 0; i < 1000000; i++){
counter += value;
}
System.out.println(counter);
}
}
It basically calculates 1000000 / 10, I know that the result won t be exact but in some pcs it prints a number that is slightly less than 100000 and in other cases it prints a number slightly greater.