1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
\r
2 // Copyright (C) INRIA
\r
3 // Copyright (C) DIGITEO - 2011 - Allan CORNET
\r
4 // Copyright (C) 2012 - Scilab Enterprises - Adeline CARNIS
\r
6 // This file must be used under the terms of the CeCILL.
\r
7 // This source file is licensed as described in the file COPYING, which
\r
8 // you should have received as part of this distribution. The terms
\r
9 // are also available at
\r
10 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
\r
12 function i = modulo(n, m)
\r
13 //i=modulo(n,m) returns n modulo m.
\r
15 [lhs, rhs] = argn(0);
\r
17 error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"modulo", 2));
\r
20 if typeof(n) <> "constant" | ~isreal(n) then
\r
21 error(msprintf(gettext("%s: Wrong type for input argument #%d: A real expected.\n"), "modulo", 1));
\r
24 if typeof(m) <> "constant" | ~isreal(m) then
\r
25 error(msprintf(gettext("%s: Wrong type for input argument #%d: A real expected.\n"), "modulo", 2));
\r
28 if size(n,'*')==1 then
\r
31 i(k) = n - int(n ./ m(k)) .* m(k);
\r
33 i(k) = n-int(n./m(k)).*m(k);
\r
34 elseif size(m,'*')==1 then
\r
37 i = n - int(n ./ m) .* m;
\r
42 if or(size(n) <> size(m)) then
\r
43 error(msprintf(gettext("%s: Wrong size for input arguments: Same size expected.\n"),"modulo"));
\r
47 i(k) = n(k) - int(n(k) ./ m(k)) .* m(k);
\r
49 i(k) = n(k) - int(n(k)./m(k)).*m(k);
\r