Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to throw EXCEPTION_FLT_UNDERFLOW?

I need a sample code, that throws EXCEPTION_FLT_UNDERFLOW. I already have code to handle that exception. Now I need sample, that throws it. Any advises?

like image 498
Pritorian Avatar asked Oct 11 '10 18:10

Pritorian


2 Answers

Assuming you want actual code that will trigger this:

#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;
}
like image 100
MSN Avatar answered Sep 21 '22 19:09

MSN


Try:

RaiseException(EXCEPTION_FLT_UNDERFLOW, EXCEPTION_NONCONTINUABLE, 0, NULL);
like image 28
Shay Erlichmen Avatar answered Sep 25 '22 19:09

Shay Erlichmen