Mercurial > hg > octave-nkf
changeset 11827:4b36e0cc57ed release-3-0-x
Handle zero values of n in binornd correctly
author | Mark van Rossum <mvanross@inf.ed.ac.uk> |
---|---|
date | Mon, 08 Sep 2008 10:49:46 -0400 |
parents | 0b1d7174a12c |
children | 4c6738504366 |
files | scripts/ChangeLog scripts/statistics/distributions/binornd.m |
diffstat | 2 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2008-09-08 Mark van Rossum <mvanross@inf.ed.ac.uk> + + * statistics/distributions/binornd.m: Handle zero values of n + correctly. + 2008-08-28 Martin Weiser <weiser2@natur.cuni.cz> * plot/scatter3.m: Doc fix.
--- a/scripts/statistics/distributions/binornd.m +++ b/scripts/statistics/distributions/binornd.m @@ -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])