- Scilab Help
- Elementary Functions
- Bitwise operations
- Complex numbers
- Discrete mathematics
- Matrix generation
- Log - exp - power
- Floating point
- Radix conversions
- Integers
- Matrix - shaping
- Matrix operations
- Search and sort
- Set operations
- Trigonometry
- &, &&
- extraction
- ind2sub
- insertion
- isempty
- isequal
- modulo
- ndims
- |, ||
- size
- sub2ind
Please note that the recommended version of Scilab is 2024.1.0. This page might be outdated.
See the recommended documentation of this function
modulo
remainder modulo m with the sign of the left operand, or of a polynomial division
pmodulo
positive euclidian remainder modulo m
Syntax
i = modulo(n,m)
i = pmodulo(n,m)
Arguments
- m, n
Scalar, vector, matrix or hypermatrix of encoded integers, reals, or polynomials with real coefficients.
m
andn
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.- i
Scalar, vector, matrix or hypermatrix of
n
's type (and inttype).i
takes the sizes of the biggerm
orn
.For polynomials, when all remainders in the arrayi
are constant (degree==0),i
is of type 1 (numbers) instead of 2 (constant polynomials).
Description
modulo()
computes i = n (modulo m)
i.e. remainder of n
divided by m
.
For polynomials, pdiv()
is called.
For numbers,
modulo()
computesi = n - m .* int (n ./ m)
. The result is negative (or null) whenn
is negative, and is positive otherwise.pmodulo()
computesi = n - |m| .* floor (n ./ |m|)
. The result is always positive or null.
![]() | 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. |
Examples
n = [1,2,10,15]; m = [2,2,3,5]; modulo(n,m) 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) pmodulo(m,5) modulo(51, n) pmodulo(51,n) modulo(m, n) pmodulo(m,n) // Polynomials modulo( %z^2+1, %z) pmodulo(%z^2+1, %z)
See also
History
Version | Description |
5.5.0 | Extension to encoded integers and to hypermatrices of encoded integers or reals. |
6.0.2 | Extension to hypermatrices of polynomials. |
Report an issue | ||
<< isequal | Elementary Functions | ndims >> |