Arithmetic Operations

This note focuses on the basic arithmetic functions; for the basic operations exposed via operators, see Matlab Matrix Operations and Matlab Array Operations.

Modulo Division

  • mod: remainder
    • mod(a,m) returns the remainder after division of a by m
    • = a - m.*floor(a./m)
    • mod(a,0) returns a
  • rem: remainder
    • rem(a,m) returns the remainder after division of a by m
    • = a - m.*fix(a./m)
    • rem(a,0) returns NaN
  • idivide: integer division
    • idivide(a,b,<opt>) returns a/b rounded according to opt
    • opt defaults to 'fix'; allowed values are 'fix', 'floor', 'ceil', 'round'

Rounding

  • round rounds half up away from 0
  • fix rounds towards 0
  • floor rounds towards negative infinity
  • ceil rounds towards positive infinity