Integer division with different round rules. The standard behavior of the an integer division such as a
./
b is to round the result to the nearest integer. This is not always the desired behavior andidivide
permits integer element-by-element division to be performed with different treatment for the fractional part of the division as determined by the op flag. op is a string with one of the values:
- "fix"
- Calculate a
./
b with the fractional part rounded towards zero.- "round"
- Calculate a
./
b with the fractional part rounded towards the nearest integer.- "floor"
- Calculate a
./
b with the fractional part rounded downwards.- "ceil"
- Calculate a
./
b with the fractional part rounded upwards.If op is not given it is assumed that it is
"fix"
. An example demonstrating these rounding rules isidivide (int8 ([-3, 3]), int8 (4), "fix") int8 ([0, 0]) idivide (int8 ([-3, 3]), int8 (4), "round") int8 ([-1, 1]) idivide (int8 ([-3, 3]), int8 (4), "ceil") int8 ([0, 1]) idivide (int8 ([-3, 3]), int8 (4), "floor") int8 ([-1, 0])