Loading
[#319] Handle euclidean division of negative Integer and Natural
Description
Euclidean division operation EDIV can be computed between int and nat (both can be divisible and divisor). When int is negative there is arithmetic underflow because fromInteger is called to perform mod operation between two nats.
To solve this, we need to compute mod of two ints first and then convert the result to nat.
Moreover, euclidean division performances differ in Michelson and in Haskell. When there is a negative divisor, Haskell produces less integer part and negative modulo while Michelson has greater integer part and positive modulo.
To solve this we just need to add 1 to the result of integer division if divisor is negative. So divMich and modMich functions was added.
Related issue(s)
Resolves #319 (closed)
✅ Checklist for your Merge Request
Related changes (conditional)
-
Tests (see short guidelines)
- If I added new functionality, I added tests covering it.
- If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
-
Documentation
Stylistic guide (mandatory)
- My commits comply with the following policy.
- My code complies with the style guide.
Edited by Alyona Antonova