# HG changeset patch # User jwe # Date 1028876463 0 # Node ID af3a0264eefcb60e8cc9ec633ab5f93a9fe67e78 # Parent 8cb8eff3f44c5a5dafc61a6f3a98d3f391a34881 [project @ 2002-08-09 07:01:03 by jwe] diff -r 8cb8eff3f44c -r af3a0264eefc scripts/general/mod.m --- a/scripts/general/mod.m Fri Aug 09 06:56:43 2002 +0000 +++ b/scripts/general/mod.m Fri Aug 09 07:01:03 2002 +0000 @@ -51,28 +51,29 @@ ## Matlab allows complex arguments, but as far as I can tell, that's a ## bunch of hooey. - if (any (any (imag (x))) || any (any (imag (y)))) + if (isreal (x) && isreal (y)) + nz = y != 0.0; + if (all (nz(:))) + ## No elements of y are zero. + r = x - y .* floor (x ./ y); + elseif (is_scalar (y)) + ## y must be zero. + r = x; + else + ## Some elements of y are zero. + if (is_scalar (x)) + r = x * ones (size (y)); + else + r = x; + x = x(nz); + endif + y = y(nz); + r(nz) = x - y .* floor (x ./ y); + endif + else error ("mod: complex arguments are not allowed"); endif - nz = y != 0.0; - if (all (nz(:))) - ## No elements of y are zero. - r = x - y .* floor (x ./ y); - elseif (is_scalar (y)) - ## y must be zero. - r = x; - else - ## Some elements of y are zero. - if (is_scalar (x)) - r = x * ones (size (y)); - else - r = x; - x = x(nz); - endif - r(nz) = x - y .* floor (x ./ y); - endif - endfunction ## empty input test