在MATLAB中,如果我这样做,realmax - 1000000 == realmax我得到一个逻辑1(真)作为答案.这是为什么?
您得到一个真实的结果,因为1000000(ie 1e6)的值远小于双精度变量的浮点相对精度,用于最大极限或接近最大极限的值.例如:
>> 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
Run Code Online (Sandbox Code Playgroud)
简而言之,最大限度(即eps(realmax))的可表示数字之间的距离大约为10^292.减去多的较小值1e6给出了刚刚被舍入到它以前的结果.