DADiSP Worksheet Functions > Function Categories > Series and Scalar Math > MOD

 

MOD

Purpose:

Determine the remainder from a division.

Syntax:

MOD(num, den)

num

-

A scalar, series, or table. The numerator value.

den

-

A scalar, series, or table. The denominator value.

Returns:

A scalar, series, or table.

Example:

mod(5,3)

 

returns 2.

Example:

W1: 1..10

W2: ravel(W1,5)

mod(W1,5)

 

returns the series: {1, 2, 3, 4, 0, 1, 2, 3, 4, 0}

Example:

mod(W2,5)

 

returns the 5x2 array:

 

{{1, 1}, 

 {2, 2}, 

 {3, 3}, 

 {4, 4}, 

 {0, 0})  

Example:

mod(12.3, -3) == –2.7

rem(12.3, -3) ==  0.3

mod(12.3, 0)  ==  12.3

Example:

mod(5.125, int(5.125))

 

returns 0.125.

 

Example:

W1: rand(5, 1) * 10

W2: mod(w1, int(w1))

 

Because W1 is positive, W2 contains the fractional part of W1.

 

Remarks:

mod(a, b) is equivalent to a % b

 

mod(a, b) has the same sign as b and rem(a, b) has the same sign as a. Both are equal if the inputs have the same sign, but differ by b if the signs differ, i.e.:

 

mod(-a, b) == rem(-a, b) + b

 

MOD works for scalars, series, and tables.

See Also:

CEILING

FIX

FLOOR

REM

ROUND