diff --git a/math/KahanSum.h b/math/KahanSum.h index e2622a0..cb0edb9 100644 --- a/math/KahanSum.h +++ b/math/KahanSum.h @@ -49,10 +49,15 @@ public: private: -#define NO_OPT __attribute__((optimize("-O0"))) +#ifdef _MSC_VER + #pragma optimize( "", off ) +#else + #pragma GCC push_options + #pragma GCC optimize ("O0") +#endif /** adjust the sum */ - void add(const T val) NO_OPT { + void add(const T val) { const T y = val - comp; const T t = sum + y; comp = (t-sum) - y; // very important line @@ -60,13 +65,19 @@ private: } /** adjust the sum */ - void sub(const T val) NO_OPT { + void sub(const T val) { const T y = val - comp; const T t = sum - y; comp = (t-sum) + y; // very important line sum = t; } +#ifdef _MSC_VER + #pragma optimize( "", on ) +#else + #pragma GCC pop_options +#endif + public: static T get(const std::vector& values, const T zero = T()) {