# HG changeset patch # User jwe # Date 1093987595 0 # Node ID 0896307b1b4831f3da6d262a6f03b9bbe8987929 # Parent f6b63ff1119b9460f61e922e6454324c44ec8b84 [project @ 2004-08-31 21:26:35 by jwe] diff -r f6b63ff1119b -r 0896307b1b48 scripts/ChangeLog --- a/scripts/ChangeLog Tue Aug 31 19:17:45 2004 +0000 +++ b/scripts/ChangeLog Tue Aug 31 21:26:35 2004 +0000 @@ -1,6 +1,17 @@ -2004-08-31 2004-08-30 David Bateman - - * (general/repmat.m): Adapt to allow integer types. +2004-08-31 John W. Eaton + + * general/isa.m: New function, from Octave-forge. + +2004-08-31 David Bateman + + * general/bitcmp.m, general/bitget.m, general/bitset.m: Remove + limitation on the use of int64 and uint64 types, and the use + of the eval. + + * general/bitset.m: Remove superfluous cast to return type, as bug + in .^ with integer types is fixed. + + * general/repmat.m: Adapt to allow integer types. 2004-08-31 Paul Kienzle diff -r f6b63ff1119b -r 0896307b1b48 scripts/general/bitcmp.m --- a/scripts/general/bitcmp.m Tue Aug 31 19:17:45 2004 +0000 +++ b/scripts/general/bitcmp.m Tue Aug 31 21:26:35 2004 +0000 @@ -39,25 +39,47 @@ usage ("bitcmp (A, n)"); endif - cname = class (A); - if (strcmp (cname, "double")) + if (isa (A, "double")) Bmax = bitmax; Amax = log2 (Bmax) + 1; - elseif strcmp ("uint", substr (cname, 1, 4)) - Bmax = intmax (cname); - Amax = eval ([cname, " (log2 (double (intmax (cname))) + 1);"]); + _conv = @double; else - Bmax = eval ([cname, " (-1);"]); - Amax = eval ([cname, " (log2 (double (intmax (cname))) + 2);"]); + if (isa (A, "uint8")) + Amax = 8; + _conv = @uint8; + elseif (isa (A, "uint16")) + Amax = 16; + _conv = @uint16; + elseif (isa (A, "uint32")) + Amax = 32; + _conv = @uint32; + elseif (isa (A, "uint64")) + Amax = 64; + _conv = @uint64; + elseif (isa (A, "int8")) + Amax = 8; + _conv = @int8; + elseif (isa (A, "int16")) + Amax = 16; + _conv = @int16; + elseif (isa (A, "int32")) + Amax = 32; + _conv = @int32; + elseif (isa (A, "int64")) + Amax = 64; + _conv = @int64; + else + error ("invalid class %s", class (A)); + endif + Bmax = intmax (class (A)); endif - Aone = eval ([ cname, "(1);"]); if (nargin == 2) - m = eval ([cname, " (n(:));"]); - if (any (m < Aone) || any (m > Amax)) + m = double (n(:)); + if (any (m < 1) || any (m > Amax)) error ("n must be in the range [1,%d]", Amax); endif - X = bitxor (A, bitshift (Bmax, -n)); + X = bitxor (A, bitshift (Bmax, -int8(n))); else X = bitxor (A, Bmax); endif diff -r f6b63ff1119b -r 0896307b1b48 scripts/general/bitget.m --- a/scripts/general/bitget.m Tue Aug 31 19:17:45 2004 +0000 +++ b/scripts/general/bitget.m Tue Aug 31 21:26:35 2004 +0000 @@ -34,21 +34,43 @@ usage ("bitget (A, n)"); endif - cname = class (A); - if (strcmp (cname, "double")) - Amax = log2 (bitmax) + 1; - elseif strcmp ("uint", substr (cname, 1, 4)) - Amax = eval ([cname, " (log2 (double (intmax (cname))) + 1);"]); + if (isa (A, "double")) + Amax = log2 (Bmax) + 1; + _conv = @double; else - Amax = eval ([cname, " (log2 (double (intmax (cname))) + 2);"]); + if (isa (A, "uint8")) + Amax = 8; + _conv = @uint8; + elseif (isa (A, "uint16")) + Amax = 16; + _conv = @uint16; + elseif (isa (A, "uint32")) + Amax = 32; + _conv = @uint32; + elseif (isa (A, "uint64")) + Amax = 64; + _conv = @uint64; + elseif (isa (A, "int8")) + Amax = 8; + _conv = @int8; + elseif (isa (A, "int16")) + Amax = 16; + _conv = @int16; + elseif (isa (A, "int32")) + Amax = 32; + _conv = @int32; + elseif (isa (A, "int64")) + Amax = 64; + _conv = @int64; + else + error ("invalid class %s", class (A)); + endif endif - Aone = eval ([ cname, "(1);"]); - m = eval ([cname, " (n(:));"]); - if (any (m < Aone) || any (m > Amax)) + m = double (n(:)); + if (any (m < 1) || any (m > Amax)) error ("n must be in the range [1,%d]", Amax); endif - X = eval (["bitand (A, ", cname, " (2) .^ (", cname, " (n) - Aone)) != ", cname, "(0);"]); - + X = bitand (A, bitshift (_conv (1), uint8 (n) - uint8 (1))) != _conv (0); endfunction diff -r f6b63ff1119b -r 0896307b1b48 scripts/general/bitset.m --- a/scripts/general/bitset.m Tue Aug 31 19:17:45 2004 +0000 +++ b/scripts/general/bitset.m Tue Aug 31 21:26:35 2004 +0000 @@ -41,29 +41,51 @@ value = 1; endif - cname = class (A); - if (strcmp (cname, "double")) + if (isa (A, "double")) Bmax = bitmax; Amax = log2 (Bmax) + 1; - elseif strcmp("uint", substr (cname, 1, 4)) - Bmax = intmax (cname); - Amax = eval ([cname, " (log2 (double (intmax (cname))) + 1);"]); + _conv = @double; else - Bmax = eval ([cname, " (-1);"]); - Amax = eval ([cname, " (log2 (double (intmax (cname))) + 2);"]); + if (isa (A, "uint8")) + Amax = 8; + _conv = @uint8; + elseif (isa (A, "uint16")) + Amax = 16; + _conv = @uint16; + elseif (isa (A, "uint32")) + Amax = 32; + _conv = @uint32; + elseif (isa (A, "uint64")) + Amax = 64; + _conv = @uint64; + elseif (isa (A, "int8")) + Amax = 8; + _conv = @int8; + elseif (isa (A, "int16")) + Amax = 16; + _conv = @int16; + elseif (isa (A, "int32")) + Amax = 32; + _conv = @int32; + elseif (isa (A, "int64")) + Amax = 64; + _conv = @int64; + else + error ("invalid class %s", class (A)); + endif + Bmax = intmax (class (A)); endif - Aone = eval ([ cname, "(1);"]); - m = eval ([cname, " (n(:));"]); - if (any (m < Aone) || any (m > Amax)) + m = double (n(:)); + if (any (m < 1) || any (m > Amax)) error ("n must be in the range [1,%d]", Amax); endif - ## XXX FIXME XXX Need extra cast to cname due to bad return value of .^ - X = eval (["bitand (A, Bmax - ", cname, " (", cname, " (2) .^ (", cname, " (n) - Aone)));"]); + mask = bitshift (_conv (1), uint8 (n) - uint8 (1)); + X = bitxor (A, bitand (A, mask)); if (value) - X = eval (["bitor (A, ", cname, " (2) .^ (", cname, " (n) - Aone));"]); + X = bitor (A, mask); endif endfunction diff -r f6b63ff1119b -r 0896307b1b48 scripts/general/isa.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/general/isa.m Tue Aug 31 21:26:35 2004 +0000 @@ -0,0 +1,30 @@ +## Copyright (C) 2004 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, write to the Free +## Software Foundation, 59 Temple Place - Suite 330, Boston, MA +## 02111-1307, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {} isa (@var{x}, @var{class}) +## Return true if @var{x} is a value from the class @var{class}. +## @end deftypefn + +## Author: Paul Kienzle +## Adapted-by: jwe + +function retval = isa (x, cname) + retval = strcmp (class (f), cname); +endfunction