Skip to content

[#319] Handle euclidean division of negative Integer and Natural

Alyona Antonova requested to merge alyoanton9/#319-handle-natural-numbers into master

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

    • I checked whether I should update the docs and did so if necessary:
    • I updated changelog files of all affected packages released to Hackage if my changes are externally visible.

Stylistic guide (mandatory)

Edited by Alyona Antonova

Merge request reports