1

So this is happening in both VS 2015 and 2017. Every time I run my application, it constantly breaks on Floating-point inexact result exception in msvcrt.dll, and if I click Continue, the exception comes up again and again. I unchecked it from Exception Settings, but I can't seem to be able to get to stop it from halting no matter what I try.

This is what I am getting:

Floating-point inexact result

Enabling or disabling Just My Code seems to have no effect, and this issue is occurring also in Visual Studio 2015 for me.

How do I resolve this, please?

Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
MathuSum Mut
  • 2,765
  • 3
  • 27
  • 59
  • 1
    Never mind breaking, why is this throwing? That's not default behavior. – MSalters Mar 05 '18 at 01:09
  • Floating-point exceptions are signaled by an arithmetic exception trap. These exceptions include: Invalid operation, division by zero, overflow, underflow, inexact result, integer overflow. Reference: https://msdn.microsoft.com/en-us/library/aa226618%28v=vs.60%29.aspx?f=255&MSPPError=-2147217396 Masking floating point exceptions has no effect. You need find out what exactly causes this exception in your code and fix it. – Fletcher Mar 05 '18 at 07:21
  • Isn't floating point pretty much always inexact? That's not a fixable property, is it? – MathuSum Mut Mar 05 '18 at 09:01
  • I still don’t think an arithmetic exception could be masked by some settings in VS. But you can use these function mentioned on this answer to check them: https://stackoverflow.com/a/15655796/9125096 – Fletcher Mar 06 '18 at 08:01

1 Answers1

0

This website states:

By default, the run-time libraries mask all floating-point exceptions.

It seems to me that your code changes this default by using one or several functions belonging to a group of functions named _clearfp(...), _controlfp(...) or _controlfp_s(...).

The solution to the problem is to set the interrupt exception mask _MCW_EM to the default value. For more information on the mask constants and values visit this website.

You can use the following code to set _MCW_EM to the default value:

    //Read
    unsigned int fp_control = 0;
    _controlfp_s(&fp_control, 0, 0);
    //Make changes
    unsigned int new_fp_control = fp_control | _EM_INVALID | _EM_DENORMAL | _EM_ZERODIVIDE | _EM_OVERFLOW | _EM_UNDERFLOW | _EM_INEXACT;
    //Update
    _controlfp_s(&fp_control, new_fp_control, _MCW_EM);

This code should fix the problem.

BlueTune
  • 1,023
  • 6
  • 18