🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators mod
This page was created by Stephanie on 2025-01-08. Last edited by Wikiadmin on 2026-07-29.

You use the Mod operator in OCL to get the integer remainder after dividing one integer by another.

Syntax

MDriven provides mod as an infix operator. Write the value to divide, followed by mod, followed by the divisor:

integerValue mod divisor

For example:

10 mod 3

The result is 1, because the integer quotient of 10 divided by 3 is 3, with 1 left over.

Use Mod in an expression

Use mod when your expression needs the remainder rather than the quotient. For example, the following expression returns the position within a group of three values:

10 mod 3
Expression Result Meaning
10 mod 3 1 10 leaves a remainder of 1 after division by 3.
10.div(3) 3 10 divided by 3 has an integer quotient of 3.

The random-string example in random also uses the member-style form value.Mod(divisor) to keep a generated index within the size of a character collection.

Mod, division, and remainder terminology

mod returns an integer remainder. Use Integer::div when you need the integer quotient instead.

Do not assume that all uses of the words modulus and remainder are mathematically identical in other languages or libraries. For the C# % operator and the OCL IEEERemainder example, see Documentation:Modulus math.

For the operator definition, including its signature, see Integer::mod ( i : Integer ) : Integer.

See also