Mercurial > hg > octave-lyh
comparison scripts/general/mod.m @ 4030:22bd65326ec1
[project @ 2002-08-09 18:58:13 by jwe]
author | jwe |
---|---|
date | Fri, 09 Aug 2002 19:00:16 +0000 |
parents | af3a0264eefc |
children | 9f7ef92b50b0 |
comparison
equal
deleted
inserted
replaced
4029:2cc57b6169cf | 4030:22bd65326ec1 |
---|---|
42 | 42 |
43 if (nargin != 2) | 43 if (nargin != 2) |
44 usage ("r = mod (x, y)"); | 44 usage ("r = mod (x, y)"); |
45 endif | 45 endif |
46 | 46 |
47 if (any (size (x) != size (y)) && ! (is_scalar (x) || is_scalar (y))) | 47 if (any (size (x) != size (y)) && ! (isscalar (x) || isscalar (y))) |
48 error ("mod: argument sizes must agree"); | 48 error ("mod: argument sizes must agree"); |
49 endif | 49 endif |
50 | 50 |
51 ## Matlab allows complex arguments, but as far as I can tell, that's a | 51 ## Matlab allows complex arguments, but as far as I can tell, that's a |
52 ## bunch of hooey. | 52 ## bunch of hooey. |
54 if (isreal (x) && isreal (y)) | 54 if (isreal (x) && isreal (y)) |
55 nz = y != 0.0; | 55 nz = y != 0.0; |
56 if (all (nz(:))) | 56 if (all (nz(:))) |
57 ## No elements of y are zero. | 57 ## No elements of y are zero. |
58 r = x - y .* floor (x ./ y); | 58 r = x - y .* floor (x ./ y); |
59 elseif (is_scalar (y)) | 59 elseif (isscalar (y)) |
60 ## y must be zero. | 60 ## y must be zero. |
61 r = x; | 61 r = x; |
62 else | 62 else |
63 ## Some elements of y are zero. | 63 ## Some elements of y are zero. |
64 if (is_scalar (x)) | 64 if (isscalar (x)) |
65 r = x * ones (size (y)); | 65 r = x * ones (size (y)); |
66 else | 66 else |
67 r = x; | 67 r = x; |
68 x = x(nz); | 68 x = x(nz); |
69 endif | 69 endif |