它取决于你通过“怀孕水平”的含义。
浮动点数具有“正常”(热)数值,但也有特殊和次要数字。 如果你想确定不同的限额,则C标准预先界定了不变值:
#include <math.h>
#include <stdio.h>
#include <float.h>
int main(void)
{
printf("%30s: %g
", "FLT_EPSILON", FLT_EPSILON);
printf("%30s: %g
", "FLT_MIN", FLT_MIN);
printf("%30s: %g
", "nextafterf(0.0, 1.0)", nextafterf(0.0, 1.0));
printf("%30s: %g
", "nextafterf(1.0, 2.0)-1", (nextafterf(1.0, 2.0) - 1.0f));
puts("");
printf("%30s: %g
", "DBL_EPSILON", DBL_EPSILON);
printf("%30s: %g
", "DBL_MIN", DBL_MIN);
printf("%30s: %g
", "nextafter(0.0, 1.0)", nextafter(0.0, 1.0));
printf("%30s: %g
", "nextafter(1.0, 2.0)-1", (nextafter(1.0, 2.0) - 1.0));
puts("");
printf("%30s: %Lg
", "LDBL_EPSILON", LDBL_EPSILON);
printf("%30s: %Lg
", "LDBL_MIN", LDBL_MIN);
printf("%30s: %Lg
", "nextafterl(0.0, 1.0)", nextafterl(0.0, 1.0));
printf("%30s: %Lg
", "nextafterl(1.0, 2.0)-1", (nextafterl(1.0, 2.0) - 1.0));
return 0;
}
以上方案每类印刷4个数值:
- the difference between 1 and the least value greater than 1 in that type (TYPE
_EPSILON
),
- the minimum positive normalized value in a given type (TYPE
_MIN
). This does not include subnormal numbers,
- the minimum positive value in a given type (
nextafter
*(0
...)
). This includes subnormal numbers,
- the minimum number greater than 1. This is the same as TYPE
_EPSILON
, but calculated in a different way.
根据你“割礼”的含义,上述任何东西都对你有用。
以上方案在我的电脑上的产出如下:
FLT_EPSILON: 1.19209e-07
FLT_MIN: 1.17549e-38
nextafterf(0.0, 1.0): 1.4013e-45
nextafterf(1.0, 2.0)-1: 1.19209e-07
DBL_EPSILON: 2.22045e-16
DBL_MIN: 2.22507e-308
nextafter(0.0, 1.0): 4.94066e-324
nextafter(1.0, 2.0)-1: 2.22045e-16
LDBL_EPSILON: 1.0842e-19
LDBL_MIN: 3.3621e-4932
nextafterl(0.0, 1.0): 3.6452e-4951
nextafterl(1.0, 2.0)-1: 1.0842e-19