diff options
-rw-r--r-- | src/parseTools.js | 4 | ||||
-rw-r--r-- | tests/test_core.py | 17 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index ddfb9d01..8ce83adf 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1499,7 +1499,9 @@ function getFastValue(a, op, b, type) { } if (op in MUL_DIV) { if (op == '*') { - if (a == 0 || b == 0) { + // We can't eliminate where a or b are 0 as that would break things for creating + // a negative 0. + if ((a == 0 || b == 0) && !(type in Runtime.FLOAT_TYPES)) { return '0'; } else if (a == 1) { return b; diff --git a/tests/test_core.py b/tests/test_core.py index ea2fe49e..d1d3bab0 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1399,6 +1399,23 @@ f5: nan f6: nan ''') + def test_zero_multiplication(self): + src = ''' + #include <stdio.h> + int main(int argc, char * argv[]) { + int one = argc; + + printf("%d ", 0 * one); + printf("%d ", 0 * -one); + printf("%d ", -one * 0); + printf("%g ", 0.0 * one); + printf("%g ", 0.0 * -one); + printf("%g", -one * 0.0); + return 0; + } + ''' + self.do_run(src, '0 0 0 0 -0 -0') + def test_isnan(self): src = r''' #include <stdio.h> |