为什么在MATLAB中realmax减去仍等于realmax的值?

时间:2018-08-30 16:17:36

标签: matlab numerical-computing

在MATLAB中,如果我做realmax - 1000000 == realmax,我将得到逻辑1(真)作为答案。为什么会这样?

1 个答案:

答案 0 :(得分:6)

由于1000000(即1e6)的值比the floating point relative accuracydouble precision variable(对于最大极限或接近最大极限)的值小得多,因此您得到了真实的结果。例如:

>> realmax-1e6==realmax  % Subtract 1 million

ans =
  logical

   1       % Still equal; not big enough to register a change

>> realmax-eps(realmax)==realmax  % Subtract the distance to the next largest value

ans =
  logical

   0       % Unequal; yeah, that's big enough to matter

简而言之,可表示的数字之间的最大距离(即eps(realmax))之间的距离约为10^292。减去较小的{em> 值1e6,结果将四舍五入到以前的水平。

您可以找到有关处理浮点数herehere的更全面的说明。