需要帮助理解在#34;静态分析仪的品种:与ASTREE的比较"中提出的浮点舍入。

时间:2017-08-12 06:24:02

标签: c floating-point

% 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

任何人都可以帮助我理解第一个示例中的内部表示如何舍入到不同的值并在第二个示例中舍入到相同的值。链接到论文,我在下面给出了上面的例子。

Varieties of Static Analyzers: A Comparison with ASTREE

0 个答案:

没有答案