如何抛出 EXCEPTION_FLT_UNDERFLOW?

Pri*_*ian 5 c++ seh visual-studio-2010

我需要一个示例代码,它会抛出 EXCEPTION_FLT_UNDERFLOW。我已经有了处理该异常的代码。现在我需要样品,这会抛出它。任何建议?

MSN*_*MSN 4

假设您想要触发此操作的实际代码:

#include <float.h>

int main()
{
    _controlfp_s(NULL, 0, _MCW_EM); // enable all floating point exceptions

    float f= 1.0f;

    while (f)
    {
        f/=2.0f;
        // __asm fwait; // optional, if you want to trap the underflow sooner
    }

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