Mercurial > hg > octave-nkf
annotate src/bitfcns.cc @ 14026:3781981be535 ss-3-5-90
snapshot 3.5.90
* configure.ac (AC_INIT): Version is now 3.5.90.
(OCTAVE_API_VERSION_NUMBER): Now 46.
(OCTAVE_RELEASE_DATE): Now 2011-12-11.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 11 Dec 2011 23:18:31 -0500 |
parents | 6da23a2d7afc |
children | 72c96de7a403 |
rev | line source |
---|---|
4908 | 1 /* |
2 | |
11523 | 3 Copyright (C) 2004-2011 John W. Eaton |
4908 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4908 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4908 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "str-vec.h" | |
28 #include "quit.h" | |
29 | |
30 #include "defun.h" | |
31 #include "error.h" | |
32 #include "ov.h" | |
33 #include "ov-uint64.h" | |
4915 | 34 #include "ov-uint32.h" |
35 #include "ov-uint16.h" | |
36 #include "ov-uint8.h" | |
37 #include "ov-int64.h" | |
38 #include "ov-int32.h" | |
39 #include "ov-int16.h" | |
40 #include "ov-int8.h" | |
41 #include "ov-scalar.h" | |
42 #include "ov-re-mat.h" | |
7763
0c6b4c7d7117
Treat bool as a scalar in the bit functions
David Bateman <dbateman@free.fr>
parents:
7097
diff
changeset
|
43 #include "ov-bool.h" |
4908 | 44 |
5775 | 45 // FIXME -- could probably eliminate some code duplication by |
4908 | 46 // clever use of templates. |
47 | |
4915 | 48 #define BITOPX(OP, FNAME, RET) \ |
49 { \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
50 int nelx = x.numel (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
51 int nely = y.numel (); \ |
4915 | 52 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
53 bool is_scalar_op = (nelx == 1 || nely == 1); \ |
4915 | 54 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
55 dim_vector dvx = x.dims (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
56 dim_vector dvy = y.dims (); \ |
4915 | 57 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
58 bool is_array_op = (dvx == dvy); \ |
4915 | 59 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
60 if (is_array_op || is_scalar_op) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
61 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
62 RET result; \ |
4915 | 63 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
64 if (nelx != 1) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
65 result.resize (dvx); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
66 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
67 result.resize (dvy); \ |
4915 | 68 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
69 for (int i = 0; i < nelx; i++) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
70 if (is_scalar_op) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
71 for (int k = 0; k < nely; k++) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
72 result(i+k) = x(i) OP y(k); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
73 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
74 result(i) = x(i) OP y(i); \ |
4915 | 75 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
76 retval = result; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
77 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
78 else \ |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
79 error ("%s: size of X and Y must match, or one operand must be a scalar", FNAME); \ |
4915 | 80 } |
81 | |
4908 | 82 #define BITOP(OP, FNAME) \ |
83 \ | |
84 octave_value retval; \ | |
85 \ | |
86 int nargin = args.length (); \ | |
87 \ | |
88 if (nargin == 2) \ | |
89 { \ | |
4952 | 90 if ((args(0).class_name () == octave_scalar::static_class_name ()) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
91 || (args(0).class_name () == octave_bool::static_class_name ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
92 || (args(1).class_name () == octave_scalar::static_class_name ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
93 || (args(1).class_name () == octave_bool::static_class_name ())) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
94 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
95 bool arg0_is_int = (args(0).class_name () != \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
96 octave_scalar::static_class_name () && \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
97 args(0).class_name () != \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
98 octave_bool::static_class_name ()); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
99 bool arg1_is_int = (args(1).class_name () != \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 octave_scalar::static_class_name () && \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
101 args(1).class_name () != \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 octave_bool::static_class_name ()); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
103 \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
104 if (! (arg0_is_int || arg1_is_int)) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
105 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
106 uint64NDArray x (args(0).array_value ()); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
107 uint64NDArray y (args(1).array_value ()); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
108 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
109 BITOPX (OP, FNAME, uint64NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
110 retval = retval.array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
111 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
112 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
113 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
114 int p = (arg0_is_int ? 1 : 0); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
115 int q = (arg0_is_int ? 0 : 1); \ |
4919 | 116 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
117 NDArray dx = args(p).array_value (); \ |
4915 | 118 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
119 if (args(q).type_id () == octave_uint64_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
120 || args(q).type_id () == octave_uint64_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
121 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
122 uint64NDArray x (dx); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
123 uint64NDArray y = args(q).uint64_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
124 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
125 BITOPX (OP, FNAME, uint64NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
126 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
127 else if (args(q).type_id () == octave_uint32_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
128 || args(q).type_id () == octave_uint32_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
129 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
130 uint32NDArray x (dx); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
131 uint32NDArray y = args(q).uint32_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
132 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
133 BITOPX (OP, FNAME, uint32NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
134 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
135 else if (args(q).type_id () == octave_uint16_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
136 || args(q).type_id () == octave_uint16_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
137 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
138 uint16NDArray x (dx); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
139 uint16NDArray y = args(q).uint16_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
140 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
141 BITOPX (OP, FNAME, uint16NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
142 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
143 else if (args(q).type_id () == octave_uint8_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
144 || args(q).type_id () == octave_uint8_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
145 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
146 uint8NDArray x (dx); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
147 uint8NDArray y = args(q).uint8_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
148 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
149 BITOPX (OP, FNAME, uint8NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
150 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
151 else if (args(q).type_id () == octave_int64_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
152 || args(q).type_id () == octave_int64_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
153 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
154 int64NDArray x (dx); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
155 int64NDArray y = args(q).int64_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
156 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
157 BITOPX (OP, FNAME, int64NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
158 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
159 else if (args(q).type_id () == octave_int32_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
160 || args(q).type_id () == octave_int32_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
161 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
162 int32NDArray x (dx); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
163 int32NDArray y = args(q).int32_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
164 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
165 BITOPX (OP, FNAME, int32NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
166 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
167 else if (args(q).type_id () == octave_int16_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
168 || args(q).type_id () == octave_int16_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
169 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
170 int16NDArray x (dx); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
171 int16NDArray y = args(q).int16_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
172 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
173 BITOPX (OP, FNAME, int16NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
174 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
175 else if (args(q).type_id () == octave_int8_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
176 || args(q).type_id () == octave_int8_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
177 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
178 int8NDArray x (dx); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 int8NDArray y = args(q).int8_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
180 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
181 BITOPX (OP, FNAME, int8NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
182 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
183 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
184 error ("%s: invalid operand type", FNAME); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
185 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
186 } \ |
4952 | 187 else if (args(0).class_name () == args(1).class_name ()) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
188 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
189 if (args(0).type_id () == octave_uint64_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
190 || args(0).type_id () == octave_uint64_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
191 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
192 uint64NDArray x = args(0).uint64_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
193 uint64NDArray y = args(1).uint64_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
194 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
195 BITOPX (OP, FNAME, uint64NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
196 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
197 else if (args(0).type_id () == octave_uint32_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
198 || args(0).type_id () == octave_uint32_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
199 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
200 uint32NDArray x = args(0).uint32_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
201 uint32NDArray y = args(1).uint32_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
202 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
203 BITOPX (OP, FNAME, uint32NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
204 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
205 else if (args(0).type_id () == octave_uint16_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
206 || args(0).type_id () == octave_uint16_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
207 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
208 uint16NDArray x = args(0).uint16_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
209 uint16NDArray y = args(1).uint16_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
210 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
211 BITOPX (OP, FNAME, uint16NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
212 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
213 else if (args(0).type_id () == octave_uint8_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
214 || args(0).type_id () == octave_uint8_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
215 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
216 uint8NDArray x = args(0).uint8_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
217 uint8NDArray y = args(1).uint8_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
218 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
219 BITOPX (OP, FNAME, uint8NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
220 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
221 else if (args(0).type_id () == octave_int64_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
222 || args(0).type_id () == octave_int64_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
223 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
224 int64NDArray x = args(0).int64_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
225 int64NDArray y = args(1).int64_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
226 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
227 BITOPX (OP, FNAME, int64NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
228 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
229 else if (args(0).type_id () == octave_int32_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
230 || args(0).type_id () == octave_int32_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
231 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
232 int32NDArray x = args(0).int32_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
233 int32NDArray y = args(1).int32_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
234 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
235 BITOPX (OP, FNAME, int32NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
236 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
237 else if (args(0).type_id () == octave_int16_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
238 || args(0).type_id () == octave_int16_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
239 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
240 int16NDArray x = args(0).int16_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
241 int16NDArray y = args(1).int16_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
242 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
243 BITOPX (OP, FNAME, int16NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
244 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
245 else if (args(0).type_id () == octave_int8_matrix::static_type_id () \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
246 || args(0).type_id () == octave_int8_scalar::static_type_id ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
247 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
248 int8NDArray x = args(0).int8_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
249 int8NDArray y = args(1).int8_array_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
250 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
251 BITOPX (OP, FNAME, int8NDArray); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
252 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
253 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
254 error ("%s: invalid operand type", FNAME); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
255 } \ |
4908 | 256 else \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
257 error ("%s: must have matching operand types", FNAME); \ |
4908 | 258 } \ |
259 else \ | |
5823 | 260 print_usage (); \ |
4908 | 261 \ |
262 return retval | |
263 | |
264 DEFUN (bitand, args, , | |
265 "-*- texinfo -*-\n\ | |
266 @deftypefn {Built-in Function} {} bitand (@var{x}, @var{y})\n\ | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
267 Return the bitwise AND of non-negative integers.\n\ |
8828 | 268 @var{x}, @var{y} must be in the range [0,bitmax]\n\ |
5642 | 269 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, bitmax}\n\ |
270 @end deftypefn") | |
4908 | 271 { |
272 BITOP (&, "bitand"); | |
273 } | |
274 | |
275 DEFUN (bitor, args, , | |
276 "-*- texinfo -*-\n\ | |
277 @deftypefn {Built-in Function} {} bitor (@var{x}, @var{y})\n\ | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
278 Return the bitwise OR of non-negative integers.\n\ |
8828 | 279 @var{x}, @var{y} must be in the range [0,bitmax]\n\ |
5642 | 280 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, bitmax}\n\ |
281 @end deftypefn") | |
4908 | 282 { |
283 BITOP (|, "bitor"); | |
284 } | |
285 | |
286 DEFUN (bitxor, args, , | |
287 "-*- texinfo -*-\n\ | |
288 @deftypefn {Built-in Function} {} bitxor (@var{x}, @var{y})\n\ | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
289 Return the bitwise XOR of non-negative integers.\n\ |
8828 | 290 @var{x}, @var{y} must be in the range [0,bitmax]\n\ |
5642 | 291 @seealso{bitand, bitor, bitset, bitget, bitcmp, bitshift, bitmax}\n\ |
292 @end deftypefn") | |
4908 | 293 { |
294 BITOP (^, "bitxor"); | |
295 } | |
296 | |
5828 | 297 static int64_t |
298 bitshift (double a, int n, int64_t mask) | |
4908 | 299 { |
6108 | 300 // In the name of bug-for-bug compatibility. |
301 if (a < 0) | |
302 return -bitshift (-a, n, mask); | |
303 | |
4915 | 304 if (n > 0) |
5828 | 305 return (static_cast<int64_t> (a) << n) & mask; |
4915 | 306 else if (n < 0) |
5828 | 307 return (static_cast<int64_t> (a) >> -n) & mask; |
4915 | 308 else |
5828 | 309 return static_cast<int64_t> (a) & mask; |
4908 | 310 } |
311 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
312 static int64_t |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
313 bitshift (float a, int n, int64_t mask) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
314 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
315 // In the name of bug-for-bug compatibility. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
316 if (a < 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
317 return -bitshift (-a, n, mask); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
318 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
319 if (n > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
320 return (static_cast<int64_t> (a) << n) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
321 else if (n < 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
322 return (static_cast<int64_t> (a) >> -n) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
323 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
324 return static_cast<int64_t> (a) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
325 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
326 |
4919 | 327 // Note that the bitshift operators are undefined if shifted by more |
328 // bits than in the type, so we need to test for the size of the | |
329 // shift. | |
330 | |
4908 | 331 #define DO_BITSHIFT(T) \ |
4919 | 332 if (! error_state) \ |
333 { \ | |
334 double d1, d2; \ | |
4908 | 335 \ |
4919 | 336 if (n.all_integers (d1, d2)) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
337 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
338 int m_nel = m.numel (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
339 int n_nel = n.numel (); \ |
4908 | 340 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
341 bool is_scalar_op = (m_nel == 1 || n_nel == 1); \ |
4908 | 342 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
343 dim_vector m_dv = m.dims (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
344 dim_vector n_dv = n.dims (); \ |
4919 | 345 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
346 bool is_array_op = (m_dv == n_dv); \ |
4908 | 347 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
348 if (is_array_op || is_scalar_op) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
349 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
350 T ## NDArray result; \ |
4908 | 351 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
352 if (m_nel != 1) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
353 result.resize (m_dv); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
354 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
355 result.resize (n_dv); \ |
4908 | 356 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
357 for (int i = 0; i < m_nel; i++) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
358 if (is_scalar_op) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
359 for (int k = 0; k < n_nel; k++) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
360 if (static_cast<int> (n(k)) >= bits_in_type) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
361 result(i+k) = 0; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
362 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
363 result(i+k) = bitshift (m(i), static_cast<int> (n(k)), mask); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
364 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
365 if (static_cast<int> (n(i)) >= bits_in_type) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
366 result(i) = 0; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
367 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
368 result(i) = bitshift (m(i), static_cast<int> (n(i)), mask); \ |
4908 | 369 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
370 retval = result; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
371 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
372 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
373 error ("bitshift: size of A and N must match, or one operand must be a scalar"); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
374 } \ |
4919 | 375 else \ |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
376 error ("bitshift: expecting integer as second argument"); \ |
4919 | 377 } |
4915 | 378 |
4919 | 379 #define DO_UBITSHIFT(T, N) \ |
380 do \ | |
381 { \ | |
4920 | 382 int bits_in_type = octave_ ## T :: nbits (); \ |
4919 | 383 T ## NDArray m = m_arg.T ## _array_value (); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
384 octave_ ## T mask = octave_ ## T::max (); \ |
4920 | 385 if ((N) < bits_in_type) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
386 mask = bitshift (mask, (N) - bits_in_type); \ |
4919 | 387 else if ((N) < 1) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
388 mask = 0; \ |
4919 | 389 DO_BITSHIFT (T); \ |
390 } \ | |
4915 | 391 while (0) |
392 | |
4919 | 393 #define DO_SBITSHIFT(T, N) \ |
394 do \ | |
395 { \ | |
4920 | 396 int bits_in_type = octave_ ## T :: nbits (); \ |
4919 | 397 T ## NDArray m = m_arg.T ## _array_value (); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
398 octave_ ## T mask = octave_ ## T::max (); \ |
4920 | 399 if ((N) < bits_in_type) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
400 mask = bitshift (mask, (N) - bits_in_type); \ |
4919 | 401 else if ((N) < 1) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
402 mask = 0; \ |
9440
357cff83985d
fix signed integer shift
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
403 mask = mask | octave_ ## T :: min (); /* FIXME: 2's complement only? */ \ |
4919 | 404 DO_BITSHIFT (T); \ |
405 } \ | |
4908 | 406 while (0) |
407 | |
408 DEFUN (bitshift, args, , | |
409 "-*- texinfo -*-\n\ | |
10840 | 410 @deftypefn {Built-in Function} {} bitshift (@var{a}, @var{k})\n\ |
6678 | 411 @deftypefnx {Built-in Function} {} bitshift (@var{a}, @var{k}, @var{n})\n\ |
8492 | 412 Return a @var{k} bit shift of @var{n}-digit unsigned\n\ |
13922
6da23a2d7afc
doc: Update bitshift() docstring
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
413 integers in @var{a}. A positive @var{k} leads to a left shift;\n\ |
4920 | 414 A negative value to a right shift. If @var{n} is omitted it defaults\n\ |
415 to log2(bitmax)+1.\n\ | |
13922
6da23a2d7afc
doc: Update bitshift() docstring
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
416 @var{n} must be in the range [1,log2(bitmax)+1] usually [1,33].\n\ |
4908 | 417 \n\ |
418 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
419 @group\n\ |
7097 | 420 bitshift (eye (3), 1)\n\ |
4908 | 421 @result{}\n\ |
422 @group\n\ | |
423 2 0 0\n\ | |
424 0 2 0\n\ | |
425 0 0 2\n\ | |
426 @end group\n\ | |
427 \n\ | |
428 bitshift (10, [-2, -1, 0, 1, 2])\n\ | |
429 @result{} 2 5 10 20 40\n\ | |
6439 | 430 @c FIXME -- restore this example when third arg is allowed to be an array.\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
431 @c\n\ |
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
432 @c\n\ |
6439 | 433 @c bitshift ([1, 10], 2, [3,4])\n\ |
434 @c @result{} 4 8\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
435 @end group\n\ |
4908 | 436 @end example\n\ |
5642 | 437 @seealso{bitand, bitor, bitxor, bitset, bitget, bitcmp, bitmax}\n\ |
438 @end deftypefn") | |
4908 | 439 { |
440 octave_value retval; | |
441 | |
442 int nargin = args.length (); | |
443 | |
4915 | 444 if (nargin == 2 || nargin == 3) |
4908 | 445 { |
4915 | 446 int nbits = 64; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
447 |
4920 | 448 NDArray n = args(1).array_value (); |
449 | |
450 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
451 error ("bitshift: expecting integer as second argument"); |
4920 | 452 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
453 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
454 if (nargin == 3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
455 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
456 // FIXME -- for compatibility, we should accept an array |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
457 // or a scalar as the third argument. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
458 if (args(2).numel () > 1) |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
459 error ("bitshift: N must be a scalar integer"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
460 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
461 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
462 nbits = args(2).int_value (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
463 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
464 if (error_state) |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
465 error ("bitshift: N must be an integer"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
466 else if (nbits < 0) |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
467 error ("bitshift: N must be positive"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
468 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
469 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
470 } |
4915 | 471 |
472 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
473 return retval; |
4908 | 474 |
475 octave_value m_arg = args(0); | |
476 std::string cname = m_arg.class_name (); | |
477 | |
478 if (cname == "uint8") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
479 DO_UBITSHIFT (uint8, nbits < 8 ? nbits : 8); |
4908 | 480 else if (cname == "uint16") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
481 DO_UBITSHIFT (uint16, nbits < 16 ? nbits : 16); |
4908 | 482 else if (cname == "uint32") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
483 DO_UBITSHIFT (uint32, nbits < 32 ? nbits : 32); |
4908 | 484 else if (cname == "uint64") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
485 DO_UBITSHIFT (uint64, nbits < 64 ? nbits : 64); |
4915 | 486 else if (cname == "int8") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
487 DO_SBITSHIFT (int8, nbits < 8 ? nbits : 8); |
4915 | 488 else if (cname == "int16") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
489 DO_SBITSHIFT (int16, nbits < 16 ? nbits : 16); |
4915 | 490 else if (cname == "int32") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
491 DO_SBITSHIFT (int32, nbits < 32 ? nbits : 32); |
4915 | 492 else if (cname == "int64") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
493 DO_SBITSHIFT (int64, nbits < 64 ? nbits : 64); |
4915 | 494 else if (cname == "double") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
495 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
496 nbits = (nbits < 53 ? nbits : 53); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
497 int64_t mask = 0x1FFFFFFFFFFFFFLL; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
498 if (nbits < 53) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
499 mask = mask >> (53 - nbits); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
500 else if (nbits < 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
501 mask = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
502 int bits_in_type = 64; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
503 NDArray m = m_arg.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
504 DO_BITSHIFT ( ); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
505 } |
4908 | 506 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
507 error ("bitshift: not defined for %s objects", cname.c_str ()); |
4908 | 508 } |
509 else | |
5823 | 510 print_usage (); |
4908 | 511 |
512 return retval; | |
513 } | |
514 | |
515 DEFUN (bitmax, args, , | |
516 "-*- texinfo -*-\n\ | |
10897
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
517 @deftypefn {Built-in Function} {} bitmax ()\n\ |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
518 @deftypefnx {Built-in Function} {} bitmax (\"double\")\n\ |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
519 @deftypefnx {Built-in Function} {} bitmax (\"single\")\n\ |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
520 Return the largest integer that can be represented within a floating point\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
521 value. The default class is \"double\", but \"single\" is a valid option.\n\ |
10897
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
522 On IEEE-754 compatible systems, @code{bitmax} is @w{@math{2^{53} - 1}}.\n\ |
4915 | 523 @end deftypefn") |
524 { | |
525 octave_value retval; | |
10897
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
526 std::string cname = "double"; |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
527 int nargin = args.length (); |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
528 |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
529 if (nargin == 1 && args(0).is_string ()) |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
530 cname = args(0).string_value (); |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
531 else if (nargin != 0) |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
532 { |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
533 print_usage (); |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
534 return retval; |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
535 } |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
536 |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
537 if (cname == "double") |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
538 retval = (static_cast<double> (0x1FFFFFFFFFFFFFLL)); |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
539 else if (cname == "single") |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
540 retval = (static_cast<double> (0xFFFFFFL)); |
4915 | 541 else |
10897
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
542 error ("bitmax: not defined for class '%s'", cname.c_str ()); |
dbec9d590756
Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents:
10895
diff
changeset
|
543 |
4915 | 544 return retval; |
545 } | |
546 | |
547 DEFUN (intmax, args, , | |
548 "-*- texinfo -*-\n\ | |
549 @deftypefn {Built-in Function} {} intmax (@var{type})\n\ | |
5040 | 550 Return the largest integer that can be represented in an integer type.\n\ |
551 The variable @var{type} can be\n\ | |
552 \n\ | |
553 @table @code\n\ | |
554 @item int8\n\ | |
555 signed 8-bit integer.\n\ | |
10840 | 556 \n\ |
5040 | 557 @item int16\n\ |
558 signed 16-bit integer.\n\ | |
10840 | 559 \n\ |
5040 | 560 @item int32\n\ |
561 signed 32-bit integer.\n\ | |
10840 | 562 \n\ |
5040 | 563 @item int64\n\ |
564 signed 64-bit integer.\n\ | |
10840 | 565 \n\ |
5040 | 566 @item uint8\n\ |
567 unsigned 8-bit integer.\n\ | |
10840 | 568 \n\ |
5040 | 569 @item uint16\n\ |
570 unsigned 16-bit integer.\n\ | |
10840 | 571 \n\ |
5040 | 572 @item uint32\n\ |
573 unsigned 32-bit integer.\n\ | |
10840 | 574 \n\ |
5040 | 575 @item uint64\n\ |
576 unsigned 64-bit integer.\n\ | |
577 @end table\n\ | |
578 \n\ | |
579 The default for @var{type} is @code{uint32}.\n\ | |
5642 | 580 @seealso{intmin, bitmax}\n\ |
4908 | 581 @end deftypefn") |
582 { | |
583 octave_value retval; | |
4915 | 584 std::string cname = "int32"; |
585 int nargin = args.length (); | |
586 | |
4919 | 587 if (nargin == 1 && args(0).is_string ()) |
4915 | 588 cname = args(0).string_value (); |
589 else if (nargin != 0) | |
590 { | |
5823 | 591 print_usage (); |
4915 | 592 return retval; |
593 } | |
594 | |
595 if (cname == "uint8") | |
5828 | 596 retval = octave_uint8 (std::numeric_limits<uint8_t>::max ()); |
4915 | 597 else if (cname == "uint16") |
5828 | 598 retval = octave_uint16 (std::numeric_limits<uint16_t>::max ()); |
4915 | 599 else if (cname == "uint32") |
5828 | 600 retval = octave_uint32 (std::numeric_limits<uint32_t>::max ()); |
4915 | 601 else if (cname == "uint64") |
5828 | 602 retval = octave_uint64 (std::numeric_limits<uint64_t>::max ()); |
4915 | 603 else if (cname == "int8") |
5828 | 604 retval = octave_int8 (std::numeric_limits<int8_t>::max ()); |
4915 | 605 else if (cname == "int16") |
5828 | 606 retval = octave_int16 (std::numeric_limits<int16_t>::max ()); |
4915 | 607 else if (cname == "int32") |
5828 | 608 retval = octave_int32 (std::numeric_limits<int32_t>::max ()); |
4915 | 609 else if (cname == "int64") |
5828 | 610 retval = octave_int64 (std::numeric_limits<int64_t>::max ()); |
4915 | 611 else |
612 error ("intmax: not defined for '%s' objects", cname.c_str ()); | |
613 | |
614 return retval; | |
615 } | |
616 | |
617 DEFUN (intmin, args, , | |
618 "-*- texinfo -*-\n\ | |
619 @deftypefn {Built-in Function} {} intmin (@var{type})\n\ | |
5040 | 620 Return the smallest integer that can be represented in an integer type.\n\ |
621 The variable @var{type} can be\n\ | |
622 \n\ | |
623 @table @code\n\ | |
624 @item int8\n\ | |
625 signed 8-bit integer.\n\ | |
10840 | 626 \n\ |
5040 | 627 @item int16\n\ |
628 signed 16-bit integer.\n\ | |
10840 | 629 \n\ |
5040 | 630 @item int32\n\ |
631 signed 32-bit integer.\n\ | |
10840 | 632 \n\ |
5040 | 633 @item int64\n\ |
634 signed 64-bit integer.\n\ | |
10840 | 635 \n\ |
5040 | 636 @item uint8\n\ |
637 unsigned 8-bit integer.\n\ | |
10840 | 638 \n\ |
5040 | 639 @item uint16\n\ |
640 unsigned 16-bit integer.\n\ | |
10840 | 641 \n\ |
5040 | 642 @item uint32\n\ |
643 unsigned 32-bit integer.\n\ | |
10840 | 644 \n\ |
5040 | 645 @item uint64\n\ |
646 unsigned 64-bit integer.\n\ | |
647 @end table\n\ | |
648 \n\ | |
649 The default for @var{type} is @code{uint32}.\n\ | |
5642 | 650 @seealso{intmax, bitmax}\n\ |
4915 | 651 @end deftypefn") |
652 { | |
653 octave_value retval; | |
654 std::string cname = "int32"; | |
655 int nargin = args.length (); | |
656 | |
4919 | 657 if (nargin == 1 && args(0).is_string ()) |
4915 | 658 cname = args(0).string_value (); |
659 else if (nargin != 0) | |
660 { | |
5823 | 661 print_usage (); |
4915 | 662 return retval; |
663 } | |
664 | |
665 if (cname == "uint8") | |
5828 | 666 retval = octave_uint8 (std::numeric_limits<uint8_t>::min ()); |
4915 | 667 else if (cname == "uint16") |
5828 | 668 retval = octave_uint16 (std::numeric_limits<uint16_t>::min()); |
4915 | 669 else if (cname == "uint32") |
5828 | 670 retval = octave_uint32 (std::numeric_limits<uint32_t>::min ()); |
4915 | 671 else if (cname == "uint64") |
5828 | 672 retval = octave_uint64 (std::numeric_limits<uint64_t>::min ()); |
4915 | 673 else if (cname == "int8") |
5828 | 674 retval = octave_int8 (std::numeric_limits<int8_t>::min ()); |
4915 | 675 else if (cname == "int16") |
5828 | 676 retval = octave_int16 (std::numeric_limits<int16_t>::min ()); |
4915 | 677 else if (cname == "int32") |
5828 | 678 retval = octave_int32 (std::numeric_limits<int32_t>::min ()); |
4915 | 679 else if (cname == "int64") |
5828 | 680 retval = octave_int64 (std::numeric_limits<int64_t>::min ()); |
4915 | 681 else |
682 error ("intmin: not defined for '%s' objects", cname.c_str ()); | |
683 | |
4908 | 684 return retval; |
685 } | |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
686 |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
687 DEFUN (sizemax, args, , |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
688 "-*- texinfo -*-\n\ |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
689 @deftypefn {Built-in Function} {} sizemax ()\n\ |
10895
4176c5c62138
Imrove documentation string for sizemax
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
690 Return the largest value allowed for the size of an array.\n\ |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
691 If Octave is compiled with 64-bit indexing, the result is of class int64,\n\ |
10895
4176c5c62138
Imrove documentation string for sizemax
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
692 otherwise it is of class int32. The maximum array size is slightly\n\ |
4176c5c62138
Imrove documentation string for sizemax
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
693 smaller than the maximum value allowable for the relevant class as reported\n\ |
4176c5c62138
Imrove documentation string for sizemax
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
694 by @code{intmax}.\n\ |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
695 @seealso{intmax}\n\ |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
696 @end deftypefn") |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
697 { |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
698 octave_value retval; |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
699 |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
700 if (args.length () == 0) |
10830
b4ebfd675321
avoid static initialization disaster in dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents:
10811
diff
changeset
|
701 retval = octave_int<octave_idx_type> (dim_vector::dim_max ()); |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
702 else |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
703 print_usage (); |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
704 |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
705 return retval; |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
706 } |