modulo

operator

Return type:
Integer
Returns:
The remainder.
Syntax
numeric-expression modulo numeric-expression


Purpose

Use modulo to find the modulus of a number with respect to a base value. The modulus is the remainder from dividing the number by the base value.

To use BCD numbers in a modulo operation, you must import the ombcd.xmd file in your program. To use floating point numbers, import the omfloat.xmd file.

You can use values of mixed data types (for example, BCD numbers and integers) as long as you follow the rules listed in Operations with mixed data types.

Integer example:

 process
 local integer seconds initial {3700}
 local integer minutes
 local integer hours
 local integer days
 
 set minutes to seconds / 60
 set seconds to seconds modulo 60
 set hours to minutes / 60
 set minutes to minutes modulo 60
 set days to hours / 24
 set hours to minutes modulo 24
 output "Days: "
 || "d" % days
 || "; Hours: "
 || "d" % hours
 || "; Minutes: "
 || "d" % minutes
 || "; Seconds: "
 || "d" % seconds
 || "%n"
 ; Output: "Days: 0; Hours: 1; Minutes: 1; Seconds: 40"

Mixed data type example:

 import "ombcd.xmd" unprefixed
 process
 local bcd seconds initial {3700}
 local bcd minutes
 local bcd hours
 local bcd days
 
 set minutes to truncate (seconds / 60)
 set seconds to seconds modulo 60
 set hours to truncate (minutes / 60)
 set minutes to minutes modulo 60
 set days to truncate (hours / 24)
 set hours to minutes modulo 24
 output "Days: "
 || "d" % days
 || "; Hours: "
 || "d" % hours
 || "; Minutes: "
 || "d" % minutes
 || "; Seconds: "
 || "d" % seconds
 || "%n"
 ; Output: "Days: 0; Hours: 1; Minutes: 1; Seconds: 40"

Related Concepts

AltStyle によって変換されたページ (->オリジナル) /