Changeset 1275 for cpp/common/nonstd_math.cpp
- Timestamp:
- 09/09/23 15:16:31 (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/nonstd_math.cpp
r1251 r1275 88 88 } 89 89 90 91 90 namespace fpExcept 91 { //shared for all platform, using crossplatform constants, can be defined in build_config (but also conditionally changed from the code) 92 int wanted_exceptions = 93 #ifdef WANTED_FP_EXCEPTIONS 94 WANTED_FP_EXCEPTIONS; 95 #else 96 FPEX_DIV0; //default when 'WANTED_FP_EXCEPTIONS' is not defined (add more?) 97 #endif 98 } 92 99 93 100 // Idea: enable selected floating point exceptions when the app starts and disable them temporarily when dividing values in ExtValue, so that we can directly handle problematic cases there. … … 96 103 #ifdef IPHONE 97 104 //TODO! -> ? http://stackoverflow.com/questions/12762418/how-to-enable-sigfpe-signal-on-division-by-zero-in-ios-app 98 void fpExceptInit() 99 {} 100 101 void fpExceptEnable() 102 {} 103 104 void fpExceptDisable() 105 {} 105 namespace fpExcept 106 { 107 void init() {} 108 void enable() {} 109 void disable() {} 110 } 106 111 #endif 107 112 108 113 #ifdef MACOS 109 //TODO...? 110 111 void fpExceptInit() 112 {} 113 114 void fpExceptEnable() 115 {} 116 117 void fpExceptDisable() 118 {} 114 //TODO...? (even less reasons to omit this in macos :-P) 115 namespace fpExcept 116 { 117 void init() {} 118 void enable() {} 119 void disable() {} 120 } 119 121 #endif 120 122 121 123 122 124 #if defined LINUX || defined TIZEN || defined __ANDROID__ 123 124 125 #include <fenv.h> 125 126 126 static constexpr int WANTED_FP_EXCEPTIONS = FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW; 127 128 void fpExceptInit() 129 {} 130 131 void fpExceptEnable() 132 { 133 feclearexcept(WANTED_FP_EXCEPTIONS); 134 feenableexcept(WANTED_FP_EXCEPTIONS); 135 } 136 137 void fpExceptDisable() 138 { 139 fedisableexcept(WANTED_FP_EXCEPTIONS); 140 } 141 127 namespace fpExcept 128 { 129 void init() {} 130 void enable() 131 { 132 feclearexcept(wanted_exceptions); 133 feenableexcept(wanted_exceptions); 134 } 135 void disable() 136 { 137 fedisableexcept(wanted_exceptions); 138 } 139 }; 142 140 #endif 143 141 … … 146 144 #if defined(__BORLANDC__) || defined(_MSC_VER) 147 145 146 namespace fpExcept 147 { 148 148 // in Borland, there was once a problem like this: 149 149 // http://qc.embarcadero.com/wc/qcmain.aspx?d=5128 … … 177 177 unsigned int fp_control_word_muted; 178 178 179 180 void fpExceptInit() 179 void init() 181 180 { 182 181 _controlfp_s(&fp_control_word_std, 0, 0); //in Visual C++, the default value is exactly the masks listed below, and we have to turn them off to enable exceptions 183 182 // Make the new fp env same as the old one, except for the changes we're going to make 184 fp_control_word_muted = fp_control_word_std & ~ (EM_INVALID | /*EM_DENORMAL |*/ EM_ZERODIVIDE | EM_OVERFLOW /* | EM_UNDERFLOW | EM_INEXACT */); //commented out exceptions that occur during proper operation185 } 186 187 void fpExceptEnable()183 fp_control_word_muted = fp_control_word_std & ~wanted_exceptions; 184 } 185 186 void enable() 188 187 { 189 188 //_fpreset(); //not needed since we just _clearfp()... mentioned in https://stackoverflow.com/questions/4282217/visual-c-weird-behavior-after-enabling-floating-point-exceptions-compiler-b … … 193 192 } 194 193 195 void fpExceptDisable()194 void disable() 196 195 { 197 196 //_fpreset(); //not needed since we just _clearfp()... mentioned in https://stackoverflow.com/questions/4282217/visual-c-weird-behavior-after-enabling-floating-point-exceptions-compiler-b … … 200 199 _controlfp_s(&was, fp_control_word_std, _MCW_EM); 201 200 } 202 #endif 201 202 }; 203 204 #endif
Note: See TracChangeset
for help on using the changeset viewer.