Skip to content

Commit

Permalink
Clear FPU bits for non-MSVC compilers; See #353
Browse files Browse the repository at this point in the history
  • Loading branch information
ibell committed Dec 17, 2014
1 parent ef59b28 commit 55c0e89
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/CoolPropLib.cpp
Expand Up @@ -2,8 +2,12 @@
#define _CRTDBG_MAP_ALLOC
#define _CRT_SECURE_NO_WARNINGS
#include <crtdbg.h>
#else
#include <fenv.h>
#endif



#include "CoolPropLib.h"
#include "CoolProp.h"
#include "HumidAirProp.h"
Expand All @@ -16,9 +20,12 @@
// In Microsoft Excel, they seem to check the FPU exception bits and error out because of it.
// By calling the _clearfp(), we can reset these bits, and not get the error
// See also http://stackoverflow.com/questions/11685441/floating-point-error-when-calling-dll-function-from-vba/27336496#27336496
// See also http://stackoverflow.com/questions/16849009/in-linux-do-there-exist-functions-similar-to-clearfp-and-statusfp for linux and OSX
void reset_fpu()
{
#if defined(_MSC_VER)
#if defined(__STDC_IEC_559__)
feclearexcept(FE_ALL_EXCEPT);
#elif defined(_MSC_VER)
_clearfp(); // For MSVC in excel, clear the floating point error flags
#endif
}
Expand Down

0 comments on commit 55c0e89

Please sign in to comment.