% cat double-float1.c
int main () {
double x; float a, y, z, r1, r2;
a = 1.0; x = 1125899973951488.0; y = (x + a); z = (x - a);
r1 = y - z; r2 = 2 * a;
printf("(x + a) - (x - a) = %f\n", r1);
printf("2a = %f\n", r2);
}
% gcc double-float1.c >& /dev/null; ./a.out
(x + a) - (x - a) = 134217728.000000
2a = 2.000000
更改最低有效数字后
% cat double-float2.c
int main () {
double x; float a, y, z, r1, r2;
a = 1.0; x = 1125899973951487.0; y = (x + a); z = (x - a);
r1 = y - z; r2 = 2 * a;
printf("(x + a) - (x - a) = %f\n", r1);
printf("2a = %f\n", r2);
}
% gcc double-float2.c >& /dev/null; ./a.out
(x + a) - (x - a) = 0.000000
2a = 2.000000
任何人都可以帮助我理解第一个示例中的内部表示如何舍入到不同的值并在第二个示例中舍入到相同的值。链接到论文,我在下面给出了上面的例子。