You can calculate an IEEE remainder in OCL when you need the value left by a division calculation; this page is for MDriven Designer users writing numeric expressions.
Use IEEE remainder in OCL
In C#, the modulus expression 5 % 3 returns the remainder of the division. In OCL, use the IEEERemainder operation instead:
5.IEEERemainder(3)This expression returns 2.
The operation takes a number as its argument and returns an integer:
number.IEEERemainder(divisor)For example, if an OCL expression has an integer-valued attribute named EmployeeCount, you can evaluate its IEEE remainder after division by 2:
EmployeeCount.IEEERemainder(2)Do not treat IEEE remainder as modulus
IEEERemainder is not mathematically equivalent to the % remainder operator. The two operations use different formulas and can return different values for the same dividend and divisor. Use IEEERemainder when the OCL expression requires the IEEE-defined operation; do not copy a C# % expression into OCL unchanged.
For the IEEE formula and the distinction from the remainder operator, see Documentation:OCLOperators Number::ieeereminder(r:Number):Integer. For the MDriven-specific comparison with C# modulus, see Documentation:Modulus math.
Related integer division
If you need the integer quotient rather than a remainder, use Integer::div. For example, integer division determines how many complete groups a value contains, while IEEERemainder evaluates the IEEE remainder after division.
