メインコンテンツまでスキップ
バージョン:25.2

modulo, mod

  • function
  • The modulo (or mod) operator produces the modular arithmetic equivalent (the “congruent value”) of its first operand, for the modulus given by its second operand. The modulus can be thought of as the length of a number line which wraps around on itself to form a circular number system.

For positive integer values, modulo yields the integer remainder of an integer division (div) operation. For those integer cases, this produces the same result as the rem operator. Unlike the rem operator, the modulo operator can perform equivalent circular operations with non-integer values. It also returns different results than rem when one of its operands is negative.

  • Examples: +

     put 8 mod 5 —> 3
     put -8 mod 5 —> 2
     put 7.4 modulo 4.1 —> 3.3
  • Related: div, rem