annotate scripts/general/bitset.m @ 30875:5d3faba0342e

doc: Ensure documentation lists output argument when it exists for all m-files. For new users of Octave it is best to show explicit calling forms in the documentation and to show a return argument when it exists. * bp-table.cc, shift.m, accumarray.m, accumdim.m, bincoeff.m, bitcmp.m, bitget.m, bitset.m, blkdiag.m, celldisp.m, cplxpair.m, dblquad.m, flip.m, fliplr.m, flipud.m, idivide.m, int2str.m, interpft.m, logspace.m, num2str.m, polyarea.m, postpad.m, prepad.m, randi.m, repmat.m, rng.m, rot90.m, rotdim.m, structfun.m, triplequad.m, uibuttongroup.m, uicontrol.m, uipanel.m, uipushtool.m, uitoggletool.m, uitoolbar.m, waitforbuttonpress.m, help.m, __additional_help_message__.m, hsv.m, im2double.m, im2frame.m, javachk.m, usejava.m, argnames.m, char.m, formula.m, inline.m, __vectorize__.m, findstr.m, flipdim.m, strmatch.m, vectorize.m, commutation_matrix.m, cond.m, cross.m, duplication_matrix.m, expm.m, orth.m, rank.m, rref.m, trace.m, vech.m, cast.m, compare_versions.m, delete.m, dir.m, fileattrib.m, grabcode.m, gunzip.m, inputname.m, license.m, list_primes.m, ls.m, mexext.m, movefile.m, namelengthmax.m, nargoutchk.m, nthargout.m, substruct.m, swapbytes.m, ver.m, verLessThan.m, what.m, fminunc.m, fsolve.m, fzero.m, optimget.m, __fdjac__.m, matlabroot.m, savepath.m, campos.m, camroll.m, camtarget.m, camup.m, camva.m, camzoom.m, clabel.m, diffuse.m, legend.m, orient.m, rticks.m, specular.m, thetaticks.m, xlim.m, xtickangle.m, xticklabels.m, xticks.m, ylim.m, ytickangle.m, yticklabels.m, yticks.m, zlim.m, ztickangle.m, zticklabels.m, zticks.m, ellipsoid.m, isocolors.m, isonormals.m, stairs.m, surfnorm.m, __actual_axis_position__.m, __pltopt__.m, close.m, graphics_toolkit.m, pan.m, print.m, printd.m, __ghostscript__.m, __gnuplot_print__.m, __opengl_print__.m, rotate3d.m, subplot.m, zoom.m, compan.m, conv.m, poly.m, polyaffine.m, polyder.m, polyint.m, polyout.m, polyreduce.m, polyvalm.m, roots.m, prefdir.m, prefsfile.m, profexplore.m, profexport.m, profshow.m, powerset.m, unique.m, arch_rnd.m, arma_rnd.m, autoreg_matrix.m, bartlett.m, blackman.m, detrend.m, durbinlevinson.m, fftconv.m, fftfilt.m, fftshift.m, fractdiff.m, hamming.m, hanning.m, hurst.m, ifftshift.m, rectangle_lw.m, rectangle_sw.m, triangle_lw.m, sinc.m, sinetone.m, sinewave.m, spectral_adf.m, spectral_xdf.m, spencer.m, ilu.m, __sprand__.m, sprand.m, sprandn.m, sprandsym.m, treelayout.m, beta.m, betainc.m, betaincinv.m, betaln.m, cosint.m, expint.m, factorial.m, gammainc.m, gammaincinv.m, lcm.m, nthroot.m, perms.m, reallog.m, realpow.m, realsqrt.m, sinint.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m, pascal.m, rosser.m, toeplitz.m, vander.m, wilkinson.m, center.m, corr.m, cov.m, discrete_cdf.m, discrete_inv.m, discrete_pdf.m, discrete_rnd.m, empirical_cdf.m, empirical_inv.m, empirical_pdf.m, empirical_rnd.m, kendall.m, kurtosis.m, mad.m, mean.m, meansq.m, median.m, mode.m, moment.m, range.m, ranks.m, run_count.m, skewness.m, spearman.m, statistics.m, std.m, base2dec.m, bin2dec.m, blanks.m, cstrcat.m, deblank.m, dec2base.m, dec2bin.m, dec2hex.m, hex2dec.m, index.m, regexptranslate.m, rindex.m, strcat.m, strjust.m, strtrim.m, strtrunc.m, substr.m, untabify.m, __have_feature__.m, __prog_output_assert__.m, __run_test_suite__.m, example.m, fail.m, asctime.m, calendar.m, ctime.m, date.m, etime.m: Add return arguments to @deftypefn macros where they were missing. Rename variables in functions (particularly generic "retval") to match documentation. Rename some return variables for (hopefully) better clarity (e.g., 'ax' to 'hax' to indicate it is a graphics handle to an axes object).
author Rik <rik@octave.org>
date Wed, 30 Mar 2022 20:40:27 -0700
parents 796f54d4ddbf
children 74089676bd9d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2004-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26600
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
7 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## This file is part of Octave.
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23573
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23573
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
13 ## (at your option) any later version.
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
14 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
18 ## GNU General Public License for more details.
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
19 ##
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23573
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
25
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20486
diff changeset
27 ## @deftypefn {} {@var{C} =} bitset (@var{A}, @var{n})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20486
diff changeset
28 ## @deftypefnx {} {@var{C} =} bitset (@var{A}, @var{n}, @var{val})
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
29 ## Set or reset bit(s) at position @var{n} of the unsigned integers in @var{A}.
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
30 ##
25474
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
31 ## The least significant bit is @var{n} = 1. @w{@var{val} = 0} resets bits and
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
32 ## @w{@var{val} = 1} sets bits. If no @var{val} is specified it defaults to
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
33 ## 1 (set bit). All inputs must be the same size or scalars.
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
34 ##
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
35 ## Example 1: Set multiple bits
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
36 ##
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
37 ## @example
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 7017
diff changeset
38 ## @group
25474
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
39 ## x = bitset (1, 3:5)
26600
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26376
diff changeset
40 ## @result{} x =
25474
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
41 ##
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
42 ## 5 9 17
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
43 ##
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
44 ## dec2bin (x)
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
45 ## @result{}
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
46 ## 00101
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
47 ## 01001
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
48 ## 10001
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
49 ## @end group
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
50 ## @end example
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
51 ##
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
52 ## Example 2: Reset and set bits
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
53 ##
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
54 ## @example
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
55 ## @group
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
56 ## x = bitset ([15 14], 1, [0 1])
26600
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26376
diff changeset
57 ## @result{} x =
25474
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
58 ##
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
59 ## 14 15
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 7017
diff changeset
60 ## @end group
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
61 ## @end example
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20158
diff changeset
62 ## @seealso{bitand, bitor, bitxor, bitget, bitcmp, bitshift, intmax, flintmax}
5053
c08cb1098afc [project @ 2004-10-19 23:10:54 by jwe]
jwe
parents: 4950
diff changeset
63 ## @end deftypefn
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
64
25474
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
65 function C = bitset (A, n, val = true)
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4916
diff changeset
66
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27923
diff changeset
67 if (nargin < 2)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
68 print_usage ();
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
69 endif
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
70
14643
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
71 if (any (A(:) < 0))
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
72 error ("bitset: A must be >= 0");
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
73 endif
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
74
25474
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
75 [size_err, A, n, val] = common_size (A, n, val);
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
76 if (size_err)
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
77 error ("bitset: A, N, and VAL must be the same size or scalar");
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
78 endif
14643
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
79
25477
12bbea4dc840 bitset.m: Return [] for empty input for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25474
diff changeset
80 ## Special case of empty input
12bbea4dc840 bitset.m: Return [] for empty input for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25474
diff changeset
81 if (isempty (A))
12bbea4dc840 bitset.m: Return [] for empty input for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25474
diff changeset
82 C = [];
12bbea4dc840 bitset.m: Return [] for empty input for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25474
diff changeset
83 return;
12bbea4dc840 bitset.m: Return [] for empty input for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25474
diff changeset
84 endif
12bbea4dc840 bitset.m: Return [] for empty input for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25474
diff changeset
85
25474
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
86 sz = size (A);
14633
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
87 cl = class (A);
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
88
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
89 if (isfloat (A) && isreal (A))
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20158
diff changeset
90 Bmax = flintmax (cl);
17391
7d8d194f3f63 bitget.m, bitset.m: Make max bit index consistent
Mike Miller <mtmiller@ieee.org>
parents: 14643
diff changeset
91 Amax = ceil (log2 (Bmax));
14633
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
92 elseif (isinteger (A))
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
93 Bmax = intmax (cl);
17391
7d8d194f3f63 bitget.m, bitset.m: Make max bit index consistent
Mike Miller <mtmiller@ieee.org>
parents: 14643
diff changeset
94 Amax = ceil (log2 (Bmax));
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
95 else
14633
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
96 error ("bitset: invalid class %s", cl);
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
97 endif
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
98
14633
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
99 if (any ((n < 1)(:)) || any ((n > Amax)(:)))
12480
139f993936af Uppercase variables in script error strings.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
100 error ("bitset: N must be in the range [1,%d]", Amax);
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
101 endif
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
102
14633
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
103 mask = bitshift (cast (1, cl), uint8 (n) - uint8 (1));
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
104
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
105 on = logical (val);
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20852
diff changeset
106 off = ! on;
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
107
14633
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
108 if (isscalar (mask))
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
109 onmask = mask;
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
110 offmask = mask;
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
111 else
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
112 onmask = mask(on);
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
113 offmask = mask(off);
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
114 endif
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
115
14643
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
116 C = zeros (sz, cl);
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
117 C(on) = bitor (A(on), onmask);
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
118 C(off) = bitand (A(off), bitcmp (offmask));
14633
056ea51070b8 Rewrite bitset.m (bug #36458)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
119
4916
c45f14873b5e [project @ 2004-07-26 14:35:12 by jwe]
jwe
parents:
diff changeset
120 endfunction
12795
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
121
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
122
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
123 %!test
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
124 %! assert (bitset ([0, 10], [3, 3]), [4, 14]);
17392
e09cd91168d1 Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents: 17391
diff changeset
125 %! assert (bitset (single ([0, 10]), [3, 3]), single ([4, 14]));
12795
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
126 %! pfx = {"", "u"};
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
127 %! for i = 1:2
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
128 %! for prec = [8, 16, 32, 64]
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
129 %! fcn = str2func (sprintf ("%sint%d", pfx{i}, prec));
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
130 %! assert (bitset (fcn ([0, 10]), [3, 3]), fcn ([4, 14]));
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
131 %! endfor
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
132 %! endfor
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
133
25477
12bbea4dc840 bitset.m: Return [] for empty input for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25474
diff changeset
134 %!assert (bitset ([], 1), [])
12bbea4dc840 bitset.m: Return [] for empty input for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25474
diff changeset
135
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
136 %!assert <*36458> (bitset (uint8 ([1, 2;3 4]), 1, [0 1; 0 1]),
25470
7a6e35d987bb bitset.m: Expand third argument to match input size if necessary (bug #54110).
Rik <rik@octave.org>
parents: 25054
diff changeset
137 %! uint8 ([0, 3; 2 5]))
7a6e35d987bb bitset.m: Expand third argument to match input size if necessary (bug #54110).
Rik <rik@octave.org>
parents: 25054
diff changeset
138
7a6e35d987bb bitset.m: Expand third argument to match input size if necessary (bug #54110).
Rik <rik@octave.org>
parents: 25054
diff changeset
139 %!assert (bitset (1:5, 1), [1, 3, 3, 5, 5])
7a6e35d987bb bitset.m: Expand third argument to match input size if necessary (bug #54110).
Rik <rik@octave.org>
parents: 25054
diff changeset
140 %!assert (bitset (1:5, 1, [1, 1, 1, 1, 1]), [1, 3, 3, 5, 5])
7a6e35d987bb bitset.m: Expand third argument to match input size if necessary (bug #54110).
Rik <rik@octave.org>
parents: 25054
diff changeset
141 %!assert <*54110> (bitset (1:5, 1, 1), [1, 3, 3, 5, 5])
7a6e35d987bb bitset.m: Expand third argument to match input size if necessary (bug #54110).
Rik <rik@octave.org>
parents: 25054
diff changeset
142 %!assert (bitset (1:5, 1, [1, 1, 1, 1, 0]), [1, 3, 3, 5, 4])
12795
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12480
diff changeset
143
28886
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
144 ## Test input validation
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
145 %!error <Invalid call> bitset ()
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
146 %!error <Invalid call> bitset (1)
14643
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
147 %!error <A must be .= 0> bitset (-1, 2)
25474
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
148 %!error <must be the same size or scalar> bitset (1, [1 2], [1 2 3])
8109fe62ab8a bitset.m: Overhaul function for Matlab compatibility (bug #54110).
Rik <rik@octave.org>
parents: 25470
diff changeset
149 %!error <must be the same size or scalar> bitset ([1 2], [1 2 3])
14643
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
150 %!error <invalid class char> bitset ("1", 2)
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
151 %!error <N must be in the range \[1,53\]> bitset (0, 0)
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
152 %!error <N must be in the range \[1,53\]> bitset (0, 55)
17392
e09cd91168d1 Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents: 17391
diff changeset
153 %!error <N must be in the range \[1,24\]> bitset (single (0), 0)
e09cd91168d1 Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents: 17391
diff changeset
154 %!error <N must be in the range \[1,24\]> bitset (single (0), 26)
14643
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
155 %!error <N must be in the range \[1,8\]> bitset (uint8 (0), 0)
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
156 %!error <N must be in the range \[1,8\]> bitset (uint8 (0), 9)
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
157 %!error <N must be in the range \[1,7\]> bitset (int8 (0), 9)
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
158 %!error <N must be in the range \[1,15\]> bitset (int16 (0), 17)
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
159 %!error <N must be in the range \[1,16\]> bitset (uint16 (0), 17)
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
160 %!error <N must be in the range \[1,31\]> bitset (int32 (0), 33)
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
161 %!error <N must be in the range \[1,32\]> bitset (uint32 (0), 33)
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
162 %!error <N must be in the range \[1,63\]> bitset (int64 (0), 65)
d4b4080faa47 bitset.m: Update function to check for negative inputs.
Rik <octave@nomad.inbox5.com>
parents: 14639
diff changeset
163 %!error <N must be in the range \[1,64\]> bitset (uint64 (0), 65)