mdb deserves a modulus operator
mdb does not at this time have a modulus operator, but it should. This is likely a hold over from adb. While there is a '%' operator, it is for integer division as the normal division operator '/' was taken due to dereferencing. As such, I've decided to co-opt '%%' to allow someone to have a modulus operator. This is currently invalid syntax.
To test this I put together a new mdb build and tested the following:
- We correctly calculated positive and negative modulus values in a way consistent with a C program or node.js.
- We correctly handled the modulus by zero case and errored
- We did not hit the division error that the division case special cases around LONG_MIN and -1.
- That we get a syntax error if missing either argument to the modulus operator or both
- Ran the mdb_v8 test suite as an additional sanity test
I also verified that on an older mdb, using the %% would always generate a syntax error, so it should not be possible to confuse it for something else.
Updated by Electric Monk over 4 years ago
- Status changed from New to Closed
commit 7a2abfc9b29ea1ccc055443876ab57455e3e8f71 Author: Robert Mustacchi <email@example.com> Date: 2019-06-04T13:14:28.000Z 10941 mdb deserves a modulus operator Reviewed by: John Levon <firstname.lastname@example.org> Reviewed by: Patrick Mooney <email@example.com> Reviewed by: Toomas Soome <firstname.lastname@example.org> Reviewed by: Andy Fiddaman <email@example.com> Reviewed by: Gordon Ross <firstname.lastname@example.org> Approved by: Dan McDonald <email@example.com>