【发布时间】:2011-03-29 13:39:57
【问题描述】:
我正在尝试找出 C 中各种浮点格式的精度级别(即 float、double 和 long double)。这是我目前正在使用的代码:
#include <stdio.h>
#define N 100000
int main(void)
{
float max = 1.0, min = 0.0, test;
int i; /* Counter for the conditional loop */
for (i = 0; i < N; i++) {
test = (max + min) / 2.0;
if( (1.0 + test) != 1.0) /* If too high, set max to test and try again */
max = test;
if( (1.0 + test) == 1.0) /* If too low, set min to test and try again */
min = test;
}
printf("The epsilon machine is %.50lf\n", max);
return 0;
}
这给出了大约 ~2^-64 的值,正如预期的那样。但是,当我将减速更改为双打或“长双打”时,我得到相同的答案,我应该得到一个较小的值,但我没有。有人有什么想法吗?
【问题讨论】:
-
浮点数没有 23 位尾数吗?为什么你会期望 2^-64?
标签: c floating-point double floating-accuracy