scripts/general/rem.m
| changeset 10289: |
4b124317dc38 |
| parent: | c1fff751b5a8 |
| author: |
John W. Eaton <jwe@octave.org> |
| date: |
Tue Feb 09 20:58:55 2010 -0500 (59 minutes ago) |
| permissions: |
-rw-r--r-- |
| description: |
base_properties::set_children: account for hidden children |
1## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2004,
2## 2005, 2006, 2007, 2008, 2009 John W. Eaton
4## This file is part of Octave.
6## Octave is free software; you can redistribute it and/or modify it
7## under the terms of the GNU General Public License as published by
8## the Free Software Foundation; either version 3 of the License, or (at
9## your option) any later version.
11## Octave is distributed in the hope that it will be useful, but
12## WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14## General Public License for more details.
16## You should have received a copy of the GNU General Public License
17## along with Octave; see the file COPYING. If not, see
18## <http://www.gnu.org/licenses/>.
21## @deftypefn {Mapping Function} {} rem (@var{x}, @var{y})
22## Return the remainder of the division @code{@var{x} / @var{y}}, computed
23## using the expression
26## x - y .* fix (x ./ y)
29## An error message is printed if the dimensions of the arguments do not
30## agree, or if either of the arguments is complex.
36function r = rem (x, y)
42 if (! size_equal (x, y) && ! (isscalar (x) || isscalar (y)))
43 error ("rem: argument sizes must agree");
46 if (isreal (x) && isreal (y))
47 if (isinteger(x) || isinteger(y))
53 r = x - y .* cast (fix (double (x) ./ double (y)), typ);
55 r = x - y .* fix (x ./ y);
58 error ("rem: complex arguments are not allowed");
63%!assert(rem ([1, 2, 3; -1, -2, -3], 2), [1, 0, 1; -1, 0, -1]);
65%!assert(rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1]);
71%!error rem ([1, 2], [3, 4, 5]);
75%!assert(rem (uint8([1, 2, 3; -1, -2, -3]), uint8 (2)), uint8([1, 0, 1; -1, 0, -1]));
77%!assert(uint8(rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),uint8([1, 0, 1; -1, 0, -1]));
79%!error rem (uint(8),int8(5));
81%!error rem (uint8([1, 2]), uint8([3, 4, 5]));