Mercurial > octave-libgccjit
diff scripts/general/rem.m @ 7494:bd2bd04e68ca
Treat integer types for mod/rem correctly
author | David Bateman <dbateman@free.fr> |
---|---|
date | Mon, 18 Feb 2008 18:08:29 +0100 |
parents | 8b7b4f58199f |
children | eb63fbe60fab |
line wrap: on
line diff
--- a/scripts/general/rem.m Tue Feb 19 03:36:08 2008 -0500 +++ b/scripts/general/rem.m Mon Feb 18 18:08:29 2008 +0100 @@ -43,21 +43,26 @@ error ("rem: argument sizes must agree"); endif - ## Matlab allows complex arguments, but as far as I can tell, that's a - ## bunch of hooey. - if (isreal (x) && isreal (y)) - r = x - y .* fix (x ./ y); + if (isinteger(x) || isinteger(y)) + if (isinteger (x)) + typ = class (x); + else + typ = class (y); + endif + r = x - y .* cast (fix (double (x) ./ double (y)), typ); + else + r = x - y .* fix (x ./ y); + endif else error ("rem: complex arguments are not allowed"); endif endfunction -%!assert(all (all (rem ([1, 2, 3; -1, -2, -3], 2) == [1, 0, 1; -1, 0, -1]))); +%!assert(rem ([1, 2, 3; -1, -2, -3], 2), [1, 0, 1; -1, 0, -1]); -%!assert(all (all (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)) -%! == [1, 0, 1; -1, 0, -1]))); +%!assert(rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1]); %!error rem (); @@ -67,3 +72,10 @@ %!error rem (i, 1); +%!assert(rem (uint8([1, 2, 3; -1, -2, -3]), uint8 (2)), uint8([1, 0, 1; -1, 0, -1])); + +%!assert(uint8(rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),uint8([1, 0, 1; -1, 0, -1])); + +%!error rem (uint(8),int8(5)); + +%!error rem (uint8([1, 2]), uint8([3, 4, 5]));