Mercurial > octave-nkf
annotate scripts/general/bitget.m @ 20521:4bb41929286b
Deprecate bitmax.
* NEWS: Announce deprecation and replacement functions.
* scripts/deprecated/bitmax.m: New function. Add deprecation message to
docstring. Add deprecation warning to m-file.
* scripts/deprecated/module.mk: Add deprecated versions to build system.
* libinterp/corefcn/bitfcns.cc: Remove build-in function. Remove function
from docstrings.
* libinterp/corefcn/data.cc: Remove function from docstrings.
* scripts/general/bitcmp.m: Replace bitmax function calls with flintmax.
Remove function from docstrings.
* scripts/general/bitget.m: Replace bitmax function calls with flintmax.
Remove function from docstrings.
* scripts/general/bitset.m: Replace bitmax function calls with flintmax.
Remove function from docstrings.
* scripts/specfun/factor.m: Replace bitmax function calls with flintmax.
Remove function from docstrings.
* scripts/statistics/distributions/unidpdf.m: Remove function from docstrings.
* scripts/general/num2str.m: Replaced function in comment.
* doc/interpreter/doccheck/aspell-octave.en.pws: Remove functions from list.
* doc/interpreter/numbers.txi: Remove function from manual.
author | Kai T. Ohlhus <k.ohlhus@gmail.com> |
---|---|
date | Wed, 09 Sep 2015 18:43:52 +0200 |
parents | 7503499a252b |
children |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 2004-2015 David Bateman |
4916 | 2 ## |
7016 | 3 ## This file is part of Octave. |
4916 | 4 ## |
7016 | 5 ## Octave is free software; you can redistribute it and/or modify it |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
4916 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
4916 | 18 |
19 ## -*- texinfo -*- | |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
20 ## @deftypefn {Function File} {@var{c} =} bitget (@var{A}, @var{n}) |
20193
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
21 ## Return the status of bit(s) @var{n} of the unsigned integers in @var{A}. |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
22 ## |
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
23 ## The least significant bit is @var{n} = 1. |
4916 | 24 ## |
25 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
26 ## @group |
4920 | 27 ## bitget (100, 8:-1:1) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
28 ## @result{} 0 1 1 0 0 1 0 0 |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
29 ## @end group |
4916 | 30 ## @end example |
20521 | 31 ## @seealso{bitand, bitor, bitxor, bitset, bitcmp, bitshift, intmax, flintmax} |
5053 | 32 ## @end deftypefn |
4916 | 33 |
34 ## Liberally based of the version by Kai Habel from octave-forge | |
35 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
36 function C = bitget (A, n) |
4920 | 37 |
4916 | 38 if (nargin != 2) |
6046 | 39 print_usage (); |
4916 | 40 endif |
41 | |
4950 | 42 if (isa (A, "double")) |
20521 | 43 Amax = ceil (log2 (flintmax)); |
4950 | 44 _conv = @double; |
17392
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17391
diff
changeset
|
45 elseif (isa (A, "single")) |
20521 | 46 Amax = ceil (log2 (flintmax ("single"))); |
17392
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17391
diff
changeset
|
47 _conv = @single; |
4916 | 48 else |
4950 | 49 if (isa (A, "uint8")) |
50 Amax = 8; | |
51 _conv = @uint8; | |
52 elseif (isa (A, "uint16")) | |
53 Amax = 16; | |
54 _conv = @uint16; | |
55 elseif (isa (A, "uint32")) | |
56 Amax = 32; | |
57 _conv = @uint32; | |
58 elseif (isa (A, "uint64")) | |
59 Amax = 64; | |
60 _conv = @uint64; | |
61 elseif (isa (A, "int8")) | |
62 Amax = 8; | |
63 _conv = @int8; | |
64 elseif (isa (A, "int16")) | |
65 Amax = 16; | |
66 _conv = @int16; | |
67 elseif (isa (A, "int32")) | |
68 Amax = 32; | |
69 _conv = @int32; | |
70 elseif (isa (A, "int64")) | |
71 Amax = 64; | |
72 _conv = @int64; | |
73 else | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
74 error ("bitget: invalid class %s", class (A)); |
4950 | 75 endif |
4916 | 76 endif |
77 | |
4950 | 78 m = double (n(:)); |
79 if (any (m < 1) || any (m > Amax)) | |
12480
139f993936af
Uppercase variables in script error strings.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
80 error ("bitget: N must be in the range [1,%d]", Amax); |
4916 | 81 endif |
82 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
83 C = bitand (A, bitshift (_conv (1), uint8 (n) - uint8 (1))) != _conv (0); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
84 |
4916 | 85 endfunction |
12795
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
86 |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
87 |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
88 %!test |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
89 %! assert (bitget ([4, 14], [3, 3]), logical ([1, 1])); |
17392
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17391
diff
changeset
|
90 %! assert (bitget (single ([4, 14]), [3, 3]), logical ([1, 1])); |
12795
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
91 %! pfx = {"", "u"}; |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
92 %! for i = 1:2 |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
93 %! 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
|
94 %! 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
|
95 %! assert (bitget (fcn ([4, 14]), [3, 3]), logical ([1, 1])); |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
96 %! endfor |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
97 %! endfor |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
98 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
99 %!error bitget (0, 0) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
100 %!error bitget (0, 55) |
12795
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
101 |
17392
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17391
diff
changeset
|
102 %!error bitget (single (0), 0) |
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17391
diff
changeset
|
103 %!error bitget (single (0), 26) |
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17391
diff
changeset
|
104 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
105 %!error bitget (int8 (0), 9) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
106 %!error bitget (uint8 (0), 9) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
107 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
108 %!error bitget (int16 (0), 17) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
109 %!error bitget (uint16 (0), 17) |
12795
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
110 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
111 %!error bitget (int32 (0), 33) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
112 %!error bitget (uint32 (0), 33) |
12795
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
113 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
114 %!error bitget (int64 (0), 65) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
115 %!error bitget (uint64 (0), 65) |
12795
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
116 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
117 %!error bitget (1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
118 %!error bitget (1, 2, 3) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
119 |