11.04.2013 Views

UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

MOD<br />

Syntax<br />

MOD(num.expr1, num.expr2)<br />

Synonym<br />

REM<br />

Description<br />

The <strong>UniBasic</strong> MOD and REM functions return the remainder of the division of<br />

num.expr2 into num.expr1. These functions divide integers and decimals. The sign of<br />

the result is the same as that of num.expr1.<br />

The formula used by MOD and REM is:<br />

REM(x,y) = x - (INT(x/y) * y)<br />

where x and y are numeric expressions. The first expression, x, is divided by y, and<br />

INT truncates the result. UniData multiplies the resulting integer by y, and subtracts<br />

the result from the value of x.<br />

Note: The value of num.expr2 cannot be 0.<br />

Example<br />

In the following example, the program segment assigns to Z the remainder of the<br />

division of Y into X. In this case, the remainder is 2.<br />

X = 12 ; Y = 5<br />

Z = MOD(X,Y)<br />

MOD 1-471

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!