Mercurial > hg > octave-nkf
annotate scripts/general/bitget.m @ 18126:d76f790b4eec gui-release
enable do_braindead_shortcircuit_evaluation by default and deprecate
* octave.cc (maximum_braindamage): Don't call
Fdo_brainded_shortcircuit_evaluation.
* pt-exp.h (tree_expression::mark_braindead_shortcircuit): Eliminate
file name argument.
* pt-binop.h, pt-binop.cc
(tree_binary_expression::mark_braindead_shortcircuit): Likewise.
* oct-parse.in.yy (if_cmd_list1, elseif_clause, loop_command):
Eliminate argument from call to mark_braindead_shortcircuit.
* pt-binop.h, pt-binop.cc (Vdo_braindead_shortcircuit_evaluation):
Initialize to true.
(tree_binary_expression::matlab_style_short_circuit_warning): New function.
(tree_binary_expression::rvalue1): Call
matlab_style_short_circuit_warning if short circuit evaluation occurs.
(Fdo_braindead_shortcircuit_evaluation): Display deprecated warning.
Delete tests for do_braindead_shortcircuit_evaluation.
(tree_binary_expression::braindead_shortcircuit_warning_issued): New
member variable.
* NEWS: Mention change in default value and deprecated function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Dec 2013 20:51:22 -0500 |
parents | d63878346099 |
children | 4197fc428c7d |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17392
diff
changeset
|
1 ## Copyright (C) 2004-2013 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}) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
21 ## Return the status of bit(s) @var{n} of unsigned integers in @var{A} |
4916 | 22 ## the lowest significant bit is @var{n} = 1. |
23 ## | |
24 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
25 ## @group |
4920 | 26 ## 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
|
27 ## @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
|
28 ## @end group |
4916 | 29 ## @end example |
5642 | 30 ## @seealso{bitand, bitor, bitxor, bitset, bitcmp, bitshift, bitmax} |
5053 | 31 ## @end deftypefn |
4916 | 32 |
33 ## Liberally based of the version by Kai Habel from octave-forge | |
34 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
35 function C = bitget (A, n) |
4920 | 36 |
4916 | 37 if (nargin != 2) |
6046 | 38 print_usage (); |
4916 | 39 endif |
40 | |
4950 | 41 if (isa (A, "double")) |
17391
7d8d194f3f63
bitget.m, bitset.m: Make max bit index consistent
Mike Miller <mtmiller@ieee.org>
parents:
14363
diff
changeset
|
42 Amax = ceil (log2 (bitmax)); |
4950 | 43 _conv = @double; |
17392
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17391
diff
changeset
|
44 elseif (isa (A, "single")) |
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17391
diff
changeset
|
45 Amax = ceil (log2 (bitmax ("single"))); |
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17391
diff
changeset
|
46 _conv = @single; |
4916 | 47 else |
4950 | 48 if (isa (A, "uint8")) |
49 Amax = 8; | |
50 _conv = @uint8; | |
51 elseif (isa (A, "uint16")) | |
52 Amax = 16; | |
53 _conv = @uint16; | |
54 elseif (isa (A, "uint32")) | |
55 Amax = 32; | |
56 _conv = @uint32; | |
57 elseif (isa (A, "uint64")) | |
58 Amax = 64; | |
59 _conv = @uint64; | |
60 elseif (isa (A, "int8")) | |
61 Amax = 8; | |
62 _conv = @int8; | |
63 elseif (isa (A, "int16")) | |
64 Amax = 16; | |
65 _conv = @int16; | |
66 elseif (isa (A, "int32")) | |
67 Amax = 32; | |
68 _conv = @int32; | |
69 elseif (isa (A, "int64")) | |
70 Amax = 64; | |
71 _conv = @int64; | |
72 else | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
73 error ("bitget: invalid class %s", class (A)); |
4950 | 74 endif |
4916 | 75 endif |
76 | |
4950 | 77 m = double (n(:)); |
78 if (any (m < 1) || any (m > Amax)) | |
12480
139f993936af
Uppercase variables in script error strings.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
79 error ("bitget: N must be in the range [1,%d]", Amax); |
4916 | 80 endif |
81 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
82 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
|
83 |
4916 | 84 endfunction |
12795
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
85 |
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 %!test |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
88 %! 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
|
89 %! 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
|
90 %! pfx = {"", "u"}; |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
91 %! for i = 1:2 |
9e7ebbaf69ff
codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents:
12480
diff
changeset
|
92 %! 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
|
93 %! 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
|
94 %! 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
|
95 %! endfor |
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 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
98 %!error bitget (0, 0) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
99 %!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
|
100 |
17392
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17391
diff
changeset
|
101 %!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
|
102 %!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
|
103 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
104 %!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
|
105 %!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
|
106 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
107 %!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
|
108 %!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
|
109 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
110 %!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
|
111 %!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
|
112 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
113 %!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
|
114 %!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
|
115 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
116 %!error bitget (1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
117 %!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
|
118 |