You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
43 lines
1.0 KiB
9 years ago
|
#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,
|
||
|
old_excepts; // previous masks
|
||
|
|
||
|
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,
|
||
|
old_excepts; // all previous masks
|
||
|
|
||
|
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 // APPLE
|