%REM (Return Integer Remainder) 取余数
时间:2016-04-26 ┊ 阅读:3,585 次 ┊ 标签: 开发 , 编程 , 经验
%REM(n:m)
取余数
%REM returns the remainder that results from dividing operands n by m. The two
operands must be numeric values with zero decimal positions. If either operand is
a packed, zoned, or binary numeric value, the result is packed numeric. If either
operand is an integer numeric value, the result is integer. Otherwise, the result is
unsigned numeric. Float numeric operands are not allowed. The result has the
same sign as the dividend.
%REM and %DIV have the following relationship:
%REM(A:B) = A - (%DIV(A:B) * B)
If the operands are constants that can fit in 8-byte integer or unsigned fields,
constant folding is applied to the built-in function. In this case, the %REM built-in
function can be coded in the definition specifications.
example:
..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
DName++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++
D A S 10I 0 INZ(123)
D B S 10I 0 INZ(27)
D DIV S 10I 0
D REM S 10I 0
D E S 10I 0
/FREE
DIV = %DIV(A:B); // DIV is now 4
REM = %REM(A:B); // REM is now 15 %rem(123:27)=15
E = DIV*B + REM; // E is now 123
/END-FREE