Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: Français - Português - 日本語 - Русский

Please note that the recommended version of Scilab is 6.0.1. This page might be outdated.
See the recommended documentation of this function

Scilab Help >> Elementary Functions > modulo


remainder modulo m with the left operand sign


positive euclidian remainder modulo m

Calling Sequence

i = modulo(n,m)
i = pmodulo(n,m)


m, n

Scalar, vector, matrix or hypermatrix of encoded integers, reals or polynomials (Hypermatrix is not supported for polynomials). m and n must have the same type. If they are of integer type, they may be of distinct encoding length (for instance int8 and int16). If none of them is scalar, they must have the same sizes.


Scalar, vector, matrix or hypermatrix of same type (and inttype) as n. i takes the sizes of the bigger m orn.


modulo computes i = n (modulo m) i.e. remainder of n divided by m.

i = n - m .* int (n ./ m). Here the answer may be negative if n or m are negative.

pmodulo computes i = n - |m| .* floor (n ./ |m|), the answer is positive or zero.

If m contains at least one 0 value, modulo(x,m) and pmodulo(x,m) will perform a division by zero. If m is of real type, this exception will be processed according to the ieee() mode. For encoded integers, it will always yield an error.


n = [1,2,10,15];
m = [2,2,3,5];

modulo(-3, 9)
modulo(10, -4)

pmodulo(-3, 9)
pmodulo(10, -6)
pmodulo(-10, -6)

// Encoded integers
modulo( int8(-13), int16(-7))
pmodulo(int8(-13), int16(-7))
modulo( int8(-13), int16([-7 5]))
pmodulo(int8(-13), int16([-7 5]))
modulo( int8([-13 8]), int16(-7))
pmodulo(int8([-13 8]), int16(-7))
modulo( int8([-13 8]), int16([-7 5]))
pmodulo(int8([-13 8]), int16([-7 5]))

// Hypermatrices
m = grand(2,2,2,"uin",-100,100)
n = grand(2,2,2,"uin",-10 ,10);
n(n==0) = 1
modulo(m, 5)
modulo(51, n)
modulo(m, n)

// Polynomials
modulo( %z^2+1, %z)
pmodulo(%z^2+1, %z)

See also

  • unwrap — unwrap a Y(x) profile or a Z(x,y) surface. Unfold a Y(x) profile
  • ieee — set floating point exception mode


5.5.0 Extension to encoded integers and to hypermatrices of encoded integers or reals.
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 02 13:46:48 CEST 2014