C语言检测计算产生subnormal值的函数是什么?
大家好!在《C Primer Plus》中,作者提到,浮点数的运算可能会产生下溢(underflow),如果精度丢失,就会产生低于正常值(subnormal)的计算结果。并说明了C语言提供了检查计算是否会产生subnormal值的函数。但并未说明是哪个函数。我查到https://cloud.
,按照这篇文章测试。如果运算产生了上溢和下溢,并未匹配到对应的宏。程序代码:
#include <stdio.h> #include <math.h> #include <float.h> #include <fenv.h> #pragma STDC FENV_ACCESS ON void show_fe_exceptions(void) { int result; printf("exceptions raised:"); if (result = fetestexcept(FE_DIVBYZERO)) { printf(" FE_DIVBYZERO\n"); printf("result = %d\n", result); } else if (result = fetestexcept(FE_INEXACT)) { printf(" FE_INEXACT\n"); printf("result = %d\n", result); } else if (result = fetestexcept(FE_INVALID)) { printf(" FE_INVALID\n"); printf("result = %d\n", result); } else if (result = fetestexcept(FE_OVERFLOW)) { printf(" FE_OVERFLOW\n"); printf("result = %d\n", result); } else if (result = fetestexcept(FE_UNDERFLOW)) { printf(" FE_UNDERFLOW\n"); printf("result = %d\n", result); } else { printf(" no above expections\n"); printf("result = %d\n", result); } feclearexcept(FE_ALL_EXCEPT); printf("\n"); } int main(void) { printf("MATH_ERREXCEPT is %s\n\n", math_errhandling & MATH_ERREXCEPT ? "set" : "not set"); float toobig = 3.4E38 * 100.0f; printf("toobig = %e\n", toobig);///< 未产生上述异常,输出inf show_fe_exceptions(); float toosmall = 1.0 * 3.4E-65565; printf("toosmall = %e\n", toosmall);///< 未产生上述异常,输出0.000000e+00 show_fe_exceptions(); return 0; }
请问这是为什么呢?C语言检测计算产生subnormal值的函数究竟是哪个呢?
[此贴子已经被作者于2021-5-4 18:54编辑过]