# HG changeset patch # User Rik # Date 1282092338 25200 # Node ID 4a2dabfb078b140b5ef87466d440241965e0ede4 # Parent dbec9d590756360aaccb4498c373a4038952a9e4 randi.m: Check IMAX for class "single" numbers diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2010-08-17 Rik + + * general/randi.m: Add IMAX check for class "single" numbers. + 2010-08-15 Rik * general/randi.m: Add new script for random integers. diff --git a/scripts/general/randi.m b/scripts/general/randi.m --- a/scripts/general/randi.m +++ b/scripts/general/randi.m @@ -85,11 +85,14 @@ rclass = "double"; endif - ## FIXME: No check for class "single" if (strfind (rclass, "int")) if (imax > intmax (rclass)) error ("randi: require IMAX < intmax (CLASS)"); endif + elseif (strcmp (rclass, "single")) + if (imax > bitmax (rclass)) + error ("randi: require IMAX < bitmax (CLASS)"); + endif endif ## Limit set by use of class double in rand() if (imax > bitmax) @@ -132,6 +135,7 @@ %!error(randi(0)) %!error(randi([10, 1])) %!error(randi(256, "uint8")) +%!error(randi(2^25, "single")) %!error(randi(bitmax() + 1)) %!error(randi([-1, bitmax()]))