使用FLT_MANT_DIG
和DBL_MANT_DIG
,定义于<float.h>
:
#include <float.h>
#include <stdio.h>
#if FLT_RADIX != 2
#error "Floating-point base is not two."
#endif
int main(void)
{
printf("There are %d bits in the significand of a float.\n",
FLT_MANT_DIG);
printf("There are %d bits in the significand of a double.\n",
DBL_MANT_DIG);
}
但是请注意,知道多少位并不能告诉您它们是哪位。同样,OP可能需要考虑在标准化IEEE-754表示中隐含的前导1位。