# HG changeset patch # User Mark van Rossum # Date 1220885386 14400 # Node ID 83646120b54c9c69b831236c65e32e2fb37c03fd # Parent 0a48abc3593216f87bfbebd457f7ac6078fa05a6 Handle zero values of n in binornd correctly diff -r 0a48abc35932 -r 83646120b54c scripts/ChangeLog --- a/scripts/ChangeLog Mon Sep 08 10:48:25 2008 -0400 +++ b/scripts/ChangeLog Mon Sep 08 10:49:46 2008 -0400 @@ -1,3 +1,8 @@ +2008-09-08 Mark van Rossum + + * statistics/distributions/binornd.m: Handle zero values of n + correctly. + 2008-09-08 Kai Habel * plot/contourf.m: Fix case for equal-sized matrices diff -r 0a48abc35932 -r 83646120b54c scripts/statistics/distributions/binornd.m --- a/scripts/statistics/distributions/binornd.m Mon Sep 08 10:48:25 2008 -0400 +++ b/scripts/statistics/distributions/binornd.m Mon Sep 08 10:49:46 2008 -0400 @@ -75,9 +75,11 @@ endif if (isscalar (n) && isscalar (p)) - if (find (!(n > 0) | !(n < Inf) | !(n == round (n)) | + if (find (!(n >= 0) | !(n < Inf) | !(n == round (n)) | !(p >= 0) | !(p <= 1))) rnd = NaN * ones (sz); + elseif (n == 0) + rnd = zeros (sz); else nel = prod (sz); tmp = rand (n, nel); @@ -87,7 +89,7 @@ else rnd = zeros (sz); - k = find (!(n > 0) | !(n < Inf) | !(n == round (n)) | + k = find (!(n >= 0) | !(n < Inf) | !(n == round (n)) | !(p >= 0) | !(p <= 1)); if (any (k)) rnd(k) = NaN; @@ -105,3 +107,6 @@ endif endfunction + +%!assert (binornd(0, 0, 1), 0) +%!assert (binornd([0, 0], [0, 0], 1, 2), [0, 0])