Navigation

Operators and Keywords

Function List:

C++ API

: idivide (x, y, op)

Integer division with different rounding rules.

The standard behavior of integer division such as a ./ b is to round the result to the nearest integer. This is not always the desired behavior and idivide 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 towards negative infinity.

"ceil"

Calculate a ./ b with the fractional part rounded towards positive infinity.

If op is not given it defaults to "fix". An example demonstrating these rounding rules is

idivide (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), "floor")
  ⇒ int8 ([-1, 0])
idivide (int8 ([-3, 3]), int8 (4), "ceil")
  ⇒ int8 ([0, 1])

See also: ldivide, rdivide.

Package: octave