Modulo: mod
Syntax
mod ( op1 , op2 )
Input parameters
op1 |
the dividend |
op2 |
the divisor |
Examples of valid syntaxes
mod( DS_1, DS_2 )
mod ( DS_1, 5 )
mod ( 5, DS_2 )
mod ( 5, 2 )
Semantics for scalar operations
The operator mod returns the remainder of op1 divided by op2. It returns op1 if divisor op2 is 0.
For example:
| mod ( 5, 2 )
gives 1
| mod ( 5, -2 )
gives -1
| mod ( 8, 2 )
gives 0
| mod ( 9, 0 )
gives 9
Input parameters type
op1, op2
dataset { measure<number> _+ }
| component<number>
| number
Result type
result
dataset { measure<number> _+ }
| component<number>
| number
Additional Constraints
None.
Behavior
The operator has the behaviour of the “Operators applicable on two Scalar Values or Data Sets or Data Set Components” (see the section “Typical behaviours of the ML Operators”).
According to the general rules about data types, the operator can be applied also on sub-types of number, that is the type integer. If the type of both operands is integer then the result has type integer. If one of the operands is of type number, then the other operand is implicitly cast to number and therefore the result has type number.
Examples
Given the operand datasets DS_1 and DS_2:
Input DS_1 (see structure)
Id_1 |
Id_2 |
Me_1 |
Me_2 |
---|---|---|---|
10 |
A |
100 |
0.7545 |
10 |
B |
10 |
18.45 |
11 |
A |
20 |
1.87 |
11 |
B |
9 |
20.3 |
Input DS_2 (see structure)
Id_1 |
Id_2 |
Me_1 |
Me_2 |
---|---|---|---|
10 |
A |
1 |
0.25 |
10 |
C |
5 |
3.0 |
11 |
B |
2 |
2.0 |
Example 1
DS_r := mod ( DS_1, DS_2 );
results in (see structure):
Id_1 |
Id_2 |
Me_1 |
Me_2 |
---|---|---|---|
10 |
A |
0 |
0.0045 |
11 |
B |
1 |
0.3 |
Example 2
DS_r := mod ( DS_1, 15 );
results in (see structure):
Id_1 |
Id_2 |
Me_1 |
Me_2 |
---|---|---|---|
10 |
A |
10 |
0.7545 |
10 |
B |
10 |
3.45 |
11 |
A |
5 |
1.87 |
11 |
B |
9 |
12.3 |
Example 3
DS_r := DS_1[ calc Me_3 := mod( Me_1, 3.0 ) ];
results in (see structure):
Id_1 |
Id_2 |
Me_1 |
Me_2 |
Me_3 |
---|---|---|---|---|
10 |
A |
100 |
0.7545 |
1.0 |
10 |
B |
10 |
18.45 |
1.0 |
11 |
A |
20 |
1.87 |
2.0 |
11 |
B |
9 |
12.3 |
0.0 |