Mercurial > hg > octave-lyh
changeset 7773:f83be206eca1
isa.m: simplify with persistent variables
author | Bill Denney |
---|---|
date | Tue, 13 May 2008 09:57:15 -0500 |
parents | ff717f2f9feb |
children | ce52af0e4a10 |
files | scripts/ChangeLog scripts/general/isa.m |
diffstat | 2 files changed, 37 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2008-05-13 Bill Denney <bill@denney.ws> + + * general/isa.m: Use persistent cell arrays to hold class names + instead of multiple strcmp calls. + 2008-05-12 David Bateman <dbateman@free.fr> * general/isa.m: Also treat "float: and "numeric" as the class
--- a/scripts/general/isa.m +++ b/scripts/general/isa.m @@ -30,15 +30,41 @@ print_usage (); endif + persistent float_classes = {"double", "single"}; + + persistent fnum_classes = {"double", "single", ... + "uint8", "uint16", "uint32", "uint64", ... + "int8", "int16", "int32", "int64"}; + if (strcmp (cname, "float")) - retval = (strcmp (class (x), "double") || strcmp (class (x), "single")); + retval = any (strcmp (class (x), float_classes)); elseif (strcmp (cname, "fnumeric")) - retval = (strcmp (class (x), "double") || strcmp (class (x), "single") || - strcmp (class (x), "uint8") || strcmp (class (x), "uint16") || - strcmp (class (x), "uint32") || strcmp (class (x), "uint64") || - strcmp (class (x), "int8") || strcmp (class (x), "int16") || - strcmp (class (x), "int32") || strcmp (class (x), "int64")); + retval = any (strcmp (class (x), fnum_classes)); else retval = strcmp (class (x), cname); endif + endfunction + +%!assert (isa ("char", "float"), 0) +%!assert (isa (double (13), "float"), 1) +%!assert (isa (single (13), "float"), 1) +%!assert (isa (int8 (13), "float"), 0) +%!assert (isa (int16 (13), "float"), 0) +%!assert (isa (int32 (13), "float"), 0) +%!assert (isa (int64 (13), "float"), 0) +%!assert (isa (uint8 (13), "float"), 0) +%!assert (isa (uint16 (13), "float"), 0) +%!assert (isa (uint32 (13), "float"), 0) +%!assert (isa (uint64 (13), "float"), 0) +%!assert (isa ("char", "fnumeric"), 0) +%!assert (isa (double (13), "fnumeric"), 1) +%!assert (isa (single (13), "fnumeric"), 1) +%!assert (isa (int8 (13), "fnumeric"), 1) +%!assert (isa (int16 (13), "fnumeric"), 1) +%!assert (isa (int32 (13), "fnumeric"), 1) +%!assert (isa (int64 (13), "fnumeric"), 1) +%!assert (isa (uint8 (13), "fnumeric"), 1) +%!assert (isa (uint16 (13), "fnumeric"), 1) +%!assert (isa (uint32 (13), "fnumeric"), 1) +%!assert (isa (uint64 (13), "fnumeric"), 1)