Merge pull request #1127 from xorgy/preprocessor-int-min-mod-negative-one

Preprocessor: Evaluate INT_MIN % -1 to 0.
This commit is contained in:
John Kessenich 2017-10-24 08:14:38 -06:00 committed by GitHub
commit 6020995198
2 changed files with 4 additions and 1 deletions

View File

@ -1,3 +1,6 @@
#if (-2147483648 / -1) != 0
#error INT_MIN / -1 should yield 0, something went wrong.
#endif
#if (-2147483648 % -1) != 0
#error INT_MIN % -1 should yield 0, something went wrong.
#endif

View File

@ -352,7 +352,7 @@ namespace {
int op_sub(int a, int b) { return a - b; }
int op_mul(int a, int b) { return a * b; }
int op_div(int a, int b) { return a == INT_MIN && b == -1 ? 0 : a / b; }
int op_mod(int a, int b) { return a % b; }
int op_mod(int a, int b) { return a == INT_MIN && b == -1 ? 0 : a % b; }
int op_pos(int a) { return a; }
int op_neg(int a) { return -a; }
int op_cmpl(int a) { return ~a; }