如果用 C 语言编写了一个程序来感受浮点误差在重复除法中的大小。
#include <stdio.h>
int main (int argc, char* argv[]) {
if (argc < 3) {
printf("Enter a decimal number as the first positional "
"argument\n");
printf("Enter the maximum number of digits to print as the "
"second positional argument\n");
return 0;
}
long double d;
sscanf(argv[1], "%Lf", &d);
int m;
sscanf(argv[2], "%d", &m);
int i;
char format[10];
for (i = 1; i <= m; ++i) {
printf("(%d digits)\n", i);
sprintf(format, "%%.%dLf\n\n", i);
printf(format, d);
}
long double p = d;
printf("\n");
for (i = 1; i <= m; ++i) {
printf("(%Lf/10e%d with %d digits)\n", d, i, m);
p = p/(long double)10.0;
printf(format, p);
}
return 0;
}
这是使用以下参数运行时的一行输出
$ fpe 0.1 700
.
.
.
(0.100000/10e180 with 700 digits)
0.0000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000999999999999999999969819570700939858153376
736698732853283605408116087882762948991724868957176649769045358705872354052
261113540314114885779914335315639806061208847920179776799404948795506248532
485303630811119507604985596684233990126219304092175565232198569923253737561
276484626462077772036038845251286782974821021132356946292172207615386395848
331484216638642723800290357587296443408362280895970909637712494349003491485
594533190659822910753768473307578901199121901299804449081420898437500000000
000000000000000000000000000
.
.
.
在这里,我们观察到 485 位浮点噪声。这是用 gcc 4.4.3 编译的,我假设它使用 80 位扩展精度。但是,485 个十进制数字远远超过 80 位信息。所以,我的问题是,这些信息是从哪里来的?