是否允许格式化 input/output 函数引发浮点异常?

Is it allowed for formatted input/output functions to raise floating-point exceptions?

示例代码 (t0.c):

#include <stdio.h>
#include <fenv.h>

int main(void)
{
    printf("%e\n", 1.0f);
    {
#pragma STDC FENV_ACCESS ON
        return fetestexcept(FE_INEXACT) ? 1 : 0;
    }
}

如果返回1,是不是报错了?

是的。

甚至更多:不仅是“允许”,而且是“必需”。

IEEE 754-2019,5.12.2:

If rounding is necessary, they shall use correct rounding and shall correctly signal the inexact and other exceptions.

ISO/IEC 9899:202x (E) 工作草案——2020 年 12 月 11 日 N2596,附件 F.5:

The "inexact" floating-point exception is raised (once) if either conversion is inexact.392) (The second conversion may raise the "overflow" or "underflow" floating-point exception.)

The specification in this subclause assures conversion between IEC 60559 binary format and decimal character sequence follows all pertinent recommended practice.