为什么fetestexcept()有时会在浮动倍增时抱怨?

Jan*_*e S 3 c linux posix

我在C99中使用fetestexcept(),它有时会抱怨乘法浮点数给出一个不精确的结果(FE_INEXACT).当浮点变量乘以浮点文字时似乎会发生这种情况.我怎么能修改这个,所以fetestexcept()不会抱怨?

gcc -std = c99 -lm test.c

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

#pragma STDC FENV_ACCESS ON

int main(void)
{
    float a = 1.1f;
    float b = 1.2f;
    float c = a * b * 1.3f;

    int exception = fetestexcept(FE_ALL_EXCEPT);
    if(exception != 0)
    {
        printf("Exception: 0x%x\n", exception); // 0x20 FE_INEXACT
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

jan*_*neb 5

好吧,如果你对那个例外不感兴趣,不要测试FE_INEXACT吗?而不是


int exception = fetestexcept(FE_ALL_EXCEPT);
Run Code Online (Sandbox Code Playgroud)


int exception = fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT);
Run Code Online (Sandbox Code Playgroud)