🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Modulus math
This page was created by Hans.karlsen on 2021-12-04. Last edited by Wikiadmin on 2026-07-29.

You can calculate a division remainder in OCL expressions when you need to test or retain the amount left after a division.

Use remainder in OCL

Use IEEERemainder on a number and pass the divisor as its argument:

5.IEEERemainder(3)

This expression returns 2: dividing 5 by 3 leaves 2.

Expression Meaning Result
5.IEEERemainder(3) Remainder after dividing 5 by 3 2
10.IEEERemainder(3) Remainder after dividing 10 by 3 1

For the definition used by MDriven, see Number::IEEERemainder.

Choose the appropriate operator

The words modulus and remainder are often used interchangeably, but they are not mathematically identical in every definition or programming language. Choose the OCL operation that expresses the rule you are writing.

Need OCL operation Example
Calculate a remainder using the number operation documented on this page IEEERemainder 5.IEEERemainder(3) returns 2
Use the integer modulo operation mod 10 mod 3 returns 1
Use the percentage-sign modulus operator for integer cyclic logic or parity checks % Use an employee count with % to determine whether the count is even or odd.

Read Integer::mod for the integer mod operation and the modulus operator (%) for modulus examples, including cyclic logic and parity checks. OCL Number Operators lists the available basic and advanced number operations.

Comparison with C#

In C#, 5 % 3 gives the remainder 2. In OCL, use 5.IEEERemainder(3) when you specifically need the remainder operation described on this page. Do not assume that operators with similar names have identical behavior across languages; use the documented MDriven operator that matches your intended calculation.

See also