Enable FPE on Mac (#4213)

Allow #3687 to work on Mac
This commit is contained in:
Tres Finocchiaro
2018-03-09 11:41:17 -05:00
committed by GitHub
parent 0a5d056bdb
commit d2c370a953
2 changed files with 49 additions and 1 deletions

View File

@@ -461,7 +461,7 @@ IF(LMMS_BUILD_WIN32)
ENDIF(LMMS_BUILD_WIN32)
IF(WANT_DEBUG_FPE)
IF(LMMS_BUILD_LINUX)
IF(LMMS_BUILD_LINUX OR LMMS_BUILD_APPLE)
SET(LMMS_DEBUG_FPE TRUE)
SET (STATUS_DEBUG_FPE "Enabled")
ELSE()

48
include/fenv.h Normal file
View File

@@ -0,0 +1,48 @@
#pragma once
#include_next <fenv.h>
#if defined(__APPLE__) && defined(__MACH__)
// Public domain polyfill for feenableexcept on OS X
// http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c
inline int feenableexcept(unsigned int excepts)
{
static fenv_t fenv;
unsigned int new_excepts = excepts & FE_ALL_EXCEPT;
// previous masks
unsigned int old_excepts;
if (fegetenv(&fenv)) {
return -1;
}
old_excepts = fenv.__control & FE_ALL_EXCEPT;
// unmask
fenv.__control &= ~new_excepts;
fenv.__mxcsr &= ~(new_excepts << 7);
return fesetenv(&fenv) ? -1 : old_excepts;
}
inline int fedisableexcept(unsigned int excepts)
{
static fenv_t fenv;
unsigned int new_excepts = excepts & FE_ALL_EXCEPT;
// all previous masks
unsigned int old_excepts;
if (fegetenv(&fenv)) {
return -1;
}
old_excepts = fenv.__control & FE_ALL_EXCEPT;
// mask
fenv.__control |= new_excepts;
fenv.__mxcsr |= new_excepts << 7;
return fesetenv(&fenv) ? -1 : old_excepts;
}
#endif