changeset 8086:83646120b54c

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 0a48abc35932
children 7d19f4f70c61
files scripts/ChangeLog scripts/statistics/distributions/binornd.m
diffstat 2 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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  <mvanross@inf.ed.ac.uk>
+
+	* statistics/distributions/binornd.m: Handle zero values of n
+	correctly.
+
 2008-09-08  Kai Habel  <kai.habel@gmx.de>
 
         * plot/contourf.m: Fix case for equal-sized matrices
--- 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])