Mercurial > octave
annotate libinterp/corefcn/bitfcns.cc @ 26056:df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
* bitfcns.cc (Fintmax, Fintmin): Redo docstring to document new calling form.
Add Example Code to documentation showing how to call function with an integer
variable as input. Use isinteger() to check for an integer input and call
class_name() to find the class of variable. Redo BIST tests.
* accumarray.m, image.m, ind2x.m, rgb2ind.m: Replace instances of
"intmax (class (x))" with just "intmax (x)". Ditto for intmin.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 10 Nov 2018 21:42:43 -0800 |
parents | aa1064eca173 |
children | afc3d1da58e5 |
rev | line source |
---|---|
4908 | 1 /* |
2 | |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
3 Copyright (C) 2004-2018 John W. Eaton |
4908 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 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:
23220
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
4908 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
4908 | 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 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
4908 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
4908 | 25 #endif |
26 | |
17396 | 27 #include <limits> |
28 | |
4908 | 29 #include "str-vec.h" |
30 #include "quit.h" | |
31 | |
32 #include "defun.h" | |
33 #include "error.h" | |
34 #include "ov.h" | |
35 #include "ov-uint64.h" | |
4915 | 36 #include "ov-uint32.h" |
37 #include "ov-uint16.h" | |
38 #include "ov-uint8.h" | |
39 #include "ov-int64.h" | |
40 #include "ov-int32.h" | |
41 #include "ov-int16.h" | |
42 #include "ov-int8.h" | |
17392
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17390
diff
changeset
|
43 #include "ov-float.h" |
4915 | 44 #include "ov-scalar.h" |
45 #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
|
46 #include "ov-bool.h" |
4908 | 47 |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
48 #include <functional> |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
49 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
50 #if ! defined (HAVE_CXX_BITWISE_OP_TEMPLATES) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
51 namespace std |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
52 { |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
53 template <typename T> |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
54 struct bit_and |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
55 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
56 public: |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
57 T operator() (const T & op1, const T & op2) const { return (op1 & op2); } |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
58 }; |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
59 |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
60 template <typename T> |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
61 struct bit_or |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
62 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 public: |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
64 T operator() (const T & op1, const T & op2) const { return (op1 | op2); } |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
65 }; |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
66 |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
67 template <typename T> |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
68 struct bit_xor |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
69 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
70 public: |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
71 T operator() (const T & op1, const T & op2) const { return (op1 ^ op2); } |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
72 }; |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
73 } |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
74 #endif |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
75 |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
76 template <typename OP, typename T> |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
77 octave_value |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
78 bitopxx (const OP& op, const std::string& fname, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
79 const Array<T>& x, const Array<T>& y) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
80 { |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
81 int nelx = x.numel (); |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
82 int nely = y.numel (); |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
83 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
84 bool is_scalar_op = (nelx == 1 || nely == 1); |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
85 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
86 dim_vector dvx = x.dims (); |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
87 dim_vector dvy = y.dims (); |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
88 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
89 bool is_array_op = (dvx == dvy); |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
90 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
91 if (! is_array_op && ! is_scalar_op) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
92 error ("%s: size of X and Y must match, or one operand must be a scalar", |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14725
diff
changeset
|
93 fname.c_str ()); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
94 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
95 Array<T> result; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
96 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
97 if (nelx != 1) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
98 result.resize (dvx); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
99 else |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
100 result.resize (dvy); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
101 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
102 for (int i = 0; i < nelx; i++) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
103 if (is_scalar_op) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
104 for (int k = 0; k < nely; k++) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
105 result(i+k) = op (x(i), y(k)); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
106 else |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
107 result(i) = op (x(i), y(i)); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
108 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
109 return result; |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
110 } |
4908 | 111 |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
112 // Trampoline function, instantiates the proper template above, with |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
113 // reflective information hardwired. We can't hardwire this information |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
114 // in Fbitxxx DEFUNs below, because at that moment, we still don't have |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
115 // information about which integer types we need to instantiate. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
20980
diff
changeset
|
116 template <typename T> |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
117 octave_value |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
118 bitopx (const std::string& fname, const Array<T>& x, const Array<T>& y) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
119 { |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
120 if (fname == "bitand") |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
121 return bitopxx (std::bit_and<T>(), fname, x, y); |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
122 if (fname == "bitor") |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
123 return bitopxx (std::bit_or<T>(), fname, x, y); |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
124 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
125 //else (fname == "bitxor") |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
126 return bitopxx (std::bit_xor<T>(), fname, x, y); |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
127 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
128 |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
129 static inline int |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
130 bitop_arg_is_int (const octave_value& arg) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
131 { |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
132 return (arg.class_name () != octave_scalar::static_class_name () |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
133 && arg.class_name () != octave_float_scalar::static_class_name () |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
134 && arg.class_name () != octave_bool::static_class_name ()); |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
135 } |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
136 |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
137 static inline int |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
138 bitop_arg_is_bool (const octave_value& arg) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
139 { |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
140 return arg.class_name () == octave_bool::static_class_name (); |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
141 } |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
142 |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
143 static inline int |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
144 bitop_arg_is_float (const octave_value& arg) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
145 { |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
146 return arg.class_name () == octave_float_scalar::static_class_name (); |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
147 } |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
148 |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
149 octave_value |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
150 bitop (const std::string& fname, const octave_value_list& args) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
151 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
152 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
153 print_usage (); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
154 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
155 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
156 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
157 if (args(0).class_name () == octave_scalar::static_class_name () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
158 || args(0).class_name () == octave_float_scalar::static_class_name () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
159 || args(0).class_name () == octave_bool::static_class_name () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
160 || args(1).class_name () == octave_scalar::static_class_name () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
161 || args(1).class_name () == octave_float_scalar::static_class_name () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
162 || args(1).class_name () == octave_bool::static_class_name ()) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
163 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
164 bool arg0_is_int = bitop_arg_is_int (args(0)); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
165 bool arg1_is_int = bitop_arg_is_int (args(1)); |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
166 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
167 bool arg0_is_bool = bitop_arg_is_bool (args(0)); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
168 bool arg1_is_bool = bitop_arg_is_bool (args(1)); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
169 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
170 bool arg0_is_float = bitop_arg_is_float (args(0)); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
171 bool arg1_is_float = bitop_arg_is_float (args(1)); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
172 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
173 if (! (arg0_is_int || arg1_is_int)) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
174 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
175 if (arg0_is_bool && arg1_is_bool) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
176 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
177 boolNDArray x (args(0).bool_array_value ()); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
178 boolNDArray y (args(1).bool_array_value ()); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
179 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
180 retval = bitopx (fname, x, y).bool_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
181 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
182 else if (arg0_is_float && arg1_is_float) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
183 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
184 uint64NDArray x (args(0).float_array_value ()); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
185 uint64NDArray y (args(1).float_array_value ()); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
186 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
187 retval = bitopx (fname, x, y).float_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
188 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
189 else if (! (arg0_is_float || arg1_is_float)) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
190 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
191 uint64NDArray x (args(0).array_value ()); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
192 uint64NDArray y (args(1).array_value ()); |
17392
e09cd91168d1
Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents:
17390
diff
changeset
|
193 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
194 retval = bitopx (fname, x, y).array_value (); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
195 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
196 else |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
197 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
198 int p = (arg0_is_float ? 1 : 0); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
199 int q = (arg0_is_float ? 0 : 1); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
200 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
201 uint64NDArray x (args(p).array_value ()); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
202 uint64NDArray y (args(q).float_array_value ()); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
203 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
204 retval = bitopx (fname, x, y).float_array_value (); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
205 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
206 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
207 else |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
208 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
209 int p = (arg0_is_int ? 1 : 0); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
210 int q = (arg0_is_int ? 0 : 1); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
211 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
212 NDArray dx = args(p).array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
213 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
214 if (args(q).type_id () == octave_uint64_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
215 || args(q).type_id () == octave_uint64_scalar::static_type_id ()) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
216 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
217 uint64NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
218 uint64NDArray y = args(q).uint64_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
219 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
220 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
221 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
222 else if (args(q).type_id () == octave_uint32_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
223 || args(q).type_id () == octave_uint32_scalar::static_type_id ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
224 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
225 uint32NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
226 uint32NDArray y = args(q).uint32_array_value (); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
227 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
228 retval = bitopx (fname, x, y); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
229 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
230 else if (args(q).type_id () == octave_uint16_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
231 || args(q).type_id () == octave_uint16_scalar::static_type_id ()) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
232 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
233 uint16NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
234 uint16NDArray y = args(q).uint16_array_value (); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
235 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
236 retval = bitopx (fname, x, y); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
237 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
238 else if (args(q).type_id () == octave_uint8_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
239 || args(q).type_id () == octave_uint8_scalar::static_type_id ()) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
240 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
241 uint8NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
242 uint8NDArray y = args(q).uint8_array_value (); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
243 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
244 retval = bitopx (fname, x, y); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
245 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
246 else if (args(q).type_id () == octave_int64_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
247 || args(q).type_id () == octave_int64_scalar::static_type_id ()) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
248 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
249 int64NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
250 int64NDArray y = args(q).int64_array_value (); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
251 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
252 retval = bitopx (fname, x, y); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
253 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
254 else if (args(q).type_id () == octave_int32_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
255 || args(q).type_id () == octave_int32_scalar::static_type_id ()) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
256 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
257 int32NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
258 int32NDArray y = args(q).int32_array_value (); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
259 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
260 retval = bitopx (fname, x, y); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
261 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
262 else if (args(q).type_id () == octave_int16_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
263 || args(q).type_id () == octave_int16_scalar::static_type_id ()) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
264 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
265 int16NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
266 int16NDArray y = args(q).int16_array_value (); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
267 |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
268 retval = bitopx (fname, x, y); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
269 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
270 else if (args(q).type_id () == octave_int8_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
271 || args(q).type_id () == octave_int8_scalar::static_type_id ()) |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
272 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
273 int8NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
274 int8NDArray y = args(q).int8_array_value (); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
275 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
276 retval = bitopx (fname, x, y); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
277 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
278 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14725
diff
changeset
|
279 error ("%s: invalid operand type", fname.c_str ()); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
280 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
281 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
282 else if (args(0).class_name () == args(1).class_name ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
283 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
284 if (args(0).type_id () == octave_uint64_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
285 || args(0).type_id () == octave_uint64_scalar::static_type_id ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
286 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
287 uint64NDArray x = args(0).uint64_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
288 uint64NDArray y = args(1).uint64_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
289 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
290 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
291 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
292 else if (args(0).type_id () == octave_uint32_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
293 || args(0).type_id () == octave_uint32_scalar::static_type_id ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
294 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
295 uint32NDArray x = args(0).uint32_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
296 uint32NDArray y = args(1).uint32_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
297 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
298 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
299 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
300 else if (args(0).type_id () == octave_uint16_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
301 || args(0).type_id () == octave_uint16_scalar::static_type_id ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
302 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
303 uint16NDArray x = args(0).uint16_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
304 uint16NDArray y = args(1).uint16_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
305 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
306 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
307 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
308 else if (args(0).type_id () == octave_uint8_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
309 || args(0).type_id () == octave_uint8_scalar::static_type_id ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
310 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
311 uint8NDArray x = args(0).uint8_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
312 uint8NDArray y = args(1).uint8_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
313 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
314 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
315 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
316 else if (args(0).type_id () == octave_int64_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
317 || args(0).type_id () == octave_int64_scalar::static_type_id ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
318 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
319 int64NDArray x = args(0).int64_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
320 int64NDArray y = args(1).int64_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
321 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
322 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
323 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
324 else if (args(0).type_id () == octave_int32_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
325 || args(0).type_id () == octave_int32_scalar::static_type_id ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
326 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
327 int32NDArray x = args(0).int32_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
328 int32NDArray y = args(1).int32_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
329 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
330 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
331 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
332 else if (args(0).type_id () == octave_int16_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
333 || args(0).type_id () == octave_int16_scalar::static_type_id ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
334 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
335 int16NDArray x = args(0).int16_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
336 int16NDArray y = args(1).int16_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
337 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
338 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
339 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
340 else if (args(0).type_id () == octave_int8_matrix::static_type_id () |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
341 || args(0).type_id () == octave_int8_scalar::static_type_id ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
342 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
343 int8NDArray x = args(0).int8_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
344 int8NDArray y = args(1).int8_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
345 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
346 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
347 } |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
348 else |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
349 error ("%s: invalid operand type", fname.c_str ()); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
350 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
351 else |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
352 error ("%s: must have matching operand types", fname.c_str ()); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
353 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
354 return retval; |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
355 } |
4908 | 356 |
357 DEFUN (bitand, args, , | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
358 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
359 @deftypefn {} {} bitand (@var{x}, @var{y}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
360 Return the bitwise AND of non-negative integers. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
361 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
362 @var{x}, @var{y} must be in the range [0,intmax] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
363 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, intmax, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
364 @end deftypefn */) |
4908 | 365 { |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
366 return bitop ("bitand", args); |
4908 | 367 } |
368 | |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
369 /* |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
370 %!# Function bitand is tested as part of bitxor BIST tests |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
371 */ |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
372 |
4908 | 373 DEFUN (bitor, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
374 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
375 @deftypefn {} {} bitor (@var{x}, @var{y}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
376 Return the bitwise OR of non-negative integers @var{x} and @var{y}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
377 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
378 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, intmax, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
379 @end deftypefn */) |
4908 | 380 { |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
381 return bitop ("bitor", args); |
4908 | 382 } |
383 | |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
384 /* |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
385 %!# Function bitor is tested as part of bitxor BIST tests |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
386 */ |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
387 |
4908 | 388 DEFUN (bitxor, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
389 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
390 @deftypefn {} {} bitxor (@var{x}, @var{y}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
391 Return the bitwise XOR of non-negative integers @var{x} and @var{y}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
392 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
393 @seealso{bitand, bitor, bitset, bitget, bitcmp, bitshift, intmax, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
394 @end deftypefn */) |
4908 | 395 { |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
396 return bitop ("bitxor", args); |
4908 | 397 } |
398 | |
19146
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
399 /* |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
400 %!assert (bitand (true, false), false) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
401 %!assert (bitor (true, false), true) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
402 %!assert (bitxor (true, false), true) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
403 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
404 %!assert (bitand (true, true), true) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
405 %!assert (bitor (true, true), true) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
406 %!assert (bitxor (true, true), false) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
407 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
408 %!assert (bitand (true, 5), 1) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
409 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
410 %!assert (bitand (true, false), false) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
411 %!assert (bitand (true, true), true) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
412 %!assert (bitand (true, false), false) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
413 %!assert (bitand (true, false), false) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
414 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
415 ## Test idx_arg.length () == 0 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
416 %!error <size of X and Y must match> bitand ([0 0 0], [1 0]) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
417 %!error <size of X and Y must match> bitand ([0; 0; 0], [0 0 0]) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
418 */ |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
419 |
17389
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
420 template <typename T> |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
421 static int64_t |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
422 max_mantissa_value () |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
423 { |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
424 return (static_cast<int64_t> (1) << std::numeric_limits<T>::digits) - 1; |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
425 } |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
426 |
5828 | 427 static int64_t |
428 bitshift (double a, int n, int64_t mask) | |
4908 | 429 { |
6108 | 430 // In the name of bug-for-bug compatibility. |
431 if (a < 0) | |
432 return -bitshift (-a, n, mask); | |
433 | |
4915 | 434 if (n > 0) |
5828 | 435 return (static_cast<int64_t> (a) << n) & mask; |
4915 | 436 else if (n < 0) |
5828 | 437 return (static_cast<int64_t> (a) >> -n) & mask; |
4915 | 438 else |
5828 | 439 return static_cast<int64_t> (a) & mask; |
4908 | 440 } |
441 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
442 static int64_t |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
443 bitshift (float a, int n, int64_t mask) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
444 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
445 // In the name of bug-for-bug compatibility. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
446 if (a < 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
447 return -bitshift (-a, n, mask); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
448 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
449 if (n > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
450 return (static_cast<int64_t> (a) << n) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
451 else if (n < 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
452 return (static_cast<int64_t> (a) >> -n) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
453 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
454 return static_cast<int64_t> (a) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
455 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
456 |
4919 | 457 // Note that the bitshift operators are undefined if shifted by more |
458 // bits than in the type, so we need to test for the size of the | |
459 // shift. | |
460 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
461 #define DO_BITSHIFT(T) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
462 double d1, d2; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
463 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
464 if (! n.all_integers (d1, d2)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
465 error ("bitshift: K must be a scalar or array of integers"); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
466 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
467 int m_nel = m.numel (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
468 int n_nel = n.numel (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
469 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
470 bool is_scalar_op = (m_nel == 1 || n_nel == 1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
471 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
472 dim_vector m_dv = m.dims (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
473 dim_vector n_dv = n.dims (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
474 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
475 bool is_array_op = (m_dv == n_dv); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
476 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
477 if (! is_array_op && ! is_scalar_op) \ |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
478 error ("bitshift: size of A and N must match, or one operand must be a scalar"); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
479 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
480 T ## NDArray result; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
481 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
482 if (m_nel != 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
483 result.resize (m_dv); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
484 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
485 result.resize (n_dv); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
486 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
487 for (int i = 0; i < m_nel; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
488 if (is_scalar_op) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
489 for (int k = 0; k < n_nel; k++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
490 if (static_cast<int> (n(k)) >= bits_in_type) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
491 result(i+k) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
492 else \ |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
493 result(i+k) = bitshift (m(i), static_cast<int> (n(k)), mask); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
494 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
495 if (static_cast<int> (n(i)) >= bits_in_type) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
496 result(i) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
497 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
498 result(i) = bitshift (m(i), static_cast<int> (n(i)), mask); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
499 \ |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
500 retval = result; |
4915 | 501 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
502 #define DO_UBITSHIFT(T, N) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
503 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
504 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
505 int bits_in_type = octave_ ## T :: nbits (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
506 T ## NDArray m = m_arg.T ## _array_value (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
507 octave_ ## T mask = octave_ ## T::max (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
508 if ((N) < bits_in_type) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
509 mask = bitshift (mask, (N) - bits_in_type); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
510 else if ((N) < 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
511 mask = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
512 DO_BITSHIFT (T); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
513 } \ |
4915 | 514 while (0) |
515 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
516 #define DO_SBITSHIFT(T, N) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
517 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
518 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
519 int bits_in_type = octave_ ## T :: nbits (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
520 T ## NDArray m = m_arg.T ## _array_value (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
521 octave_ ## T mask = octave_ ## T::max (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
522 if ((N) < bits_in_type) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
523 mask = bitshift (mask, (N) - bits_in_type); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
524 else if ((N) < 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
525 mask = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
526 /* FIXME: 2's complement only? */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
527 mask = mask | octave_ ## T :: min (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
528 DO_BITSHIFT (T); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
529 } \ |
4908 | 530 while (0) |
531 | |
532 DEFUN (bitshift, args, , | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
533 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
534 @deftypefn {} {} bitshift (@var{a}, @var{k}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
535 @deftypefnx {} {} bitshift (@var{a}, @var{k}, @var{n}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
536 Return a @var{k} bit shift of @var{n}-digit unsigned integers in @var{a}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
537 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
538 A positive @var{k} leads to a left shift; A negative value to a right shift. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
539 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
540 If @var{n} is omitted it defaults to 64. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
541 @var{n} must be in the range [1,64]. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
542 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
543 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
544 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
545 bitshift (eye (3), 1) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
546 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
547 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
548 2 0 0 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
549 0 2 0 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
550 0 0 2 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
551 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
552 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
553 bitshift (10, [-2, -1, 0, 1, 2]) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
554 @result{} 2 5 10 20 40 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
555 @c FIXME: restore this example when third arg is allowed to be an array. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
556 @c |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
557 @c |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
558 @c bitshift ([1, 10], 2, [3,4]) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
559 @c @result{} 4 8 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
560 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
561 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
562 @seealso{bitand, bitor, bitxor, bitset, bitget, bitcmp, intmax, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
563 @end deftypefn */) |
4908 | 564 { |
565 int nargin = args.length (); | |
566 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
567 if (nargin < 2 || nargin > 3) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
568 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
569 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
570 NDArray n = args(1).xarray_value ("bitshift: K must be a scalar or array of integers"); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
571 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
572 int nbits = 64; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
573 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
574 if (nargin == 3) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
575 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
576 // FIXME: for compatibility, we should accept an array or a scalar |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
577 // as the third argument. |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
578 if (args(2).numel () > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
579 error ("bitshift: N must be a scalar integer"); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
580 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
581 nbits = args(2).xint_value ("bitshift: N must be an integer"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
582 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
583 if (nbits < 0) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
584 error ("bitshift: N must be positive"); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
585 } |
4915 | 586 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
587 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
588 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
589 octave_value m_arg = args(0); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
590 std::string cname = m_arg.class_name (); |
4908 | 591 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
592 if (cname == "double") |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
593 { |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
594 static const int bits_in_mantissa |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
595 = std::numeric_limits<double>::digits; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
596 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
597 nbits = (nbits < bits_in_mantissa ? nbits : bits_in_mantissa); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
598 int64_t mask = max_mantissa_value<double> (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
599 if (nbits < bits_in_mantissa) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
600 mask = mask >> (bits_in_mantissa - nbits); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
601 else if (nbits < 1) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
602 mask = 0; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
603 int bits_in_type = sizeof (double) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
604 * std::numeric_limits<unsigned char>::digits; |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
605 NDArray m = m_arg.array_value (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
606 DO_BITSHIFT (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
607 } |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
608 else if (cname == "uint8") |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
609 DO_UBITSHIFT (uint8, nbits < 8 ? nbits : 8); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
610 else if (cname == "uint16") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
611 DO_UBITSHIFT (uint16, nbits < 16 ? nbits : 16); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
612 else if (cname == "uint32") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
613 DO_UBITSHIFT (uint32, nbits < 32 ? nbits : 32); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
614 else if (cname == "uint64") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
615 DO_UBITSHIFT (uint64, nbits < 64 ? nbits : 64); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
616 else if (cname == "int8") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
617 DO_SBITSHIFT (int8, nbits < 8 ? nbits : 8); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
618 else if (cname == "int16") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
619 DO_SBITSHIFT (int16, nbits < 16 ? nbits : 16); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
620 else if (cname == "int32") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
621 DO_SBITSHIFT (int32, nbits < 32 ? nbits : 32); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
622 else if (cname == "int64") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
623 DO_SBITSHIFT (int64, nbits < 64 ? nbits : 64); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
624 else if (cname == "single") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
625 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
626 static const int bits_in_mantissa |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
627 = std::numeric_limits<float>::digits; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
628 nbits = (nbits < bits_in_mantissa ? nbits : bits_in_mantissa); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
629 int64_t mask = max_mantissa_value<float> (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
630 if (nbits < bits_in_mantissa) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
631 mask = mask >> (bits_in_mantissa - nbits); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
632 else if (nbits < 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
633 mask = 0; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
634 int bits_in_type = sizeof (float) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
635 * std::numeric_limits<unsigned char>::digits; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
636 FloatNDArray m = m_arg.float_array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
637 DO_BITSHIFT (Float); |
4908 | 638 } |
639 else | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
640 error ("bitshift: not defined for %s objects", cname.c_str ()); |
4908 | 641 |
642 return retval; | |
643 } | |
644 | |
19146
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
645 /* |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
646 %!assert (bitshift (uint8 (16), 1), uint8 ( 32)) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
647 %!assert (bitshift (uint16 (16), 2), uint16 ( 64)) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
648 %!assert (bitshift (uint32 (16), 3), uint32 (128)) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
649 %!assert (bitshift (uint64 (16), 4), uint64 (256)) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
650 %!assert (bitshift (uint8 (255), 1), uint8 (254)) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
651 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
652 %!error <K must be a scalar or array of integers> bitshift (16, 1.5) |
19146
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
653 %!error bitshift (16, {1}) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
654 %!error <N must be a scalar integer> bitshift (10, [-2 -1 0 1 2], [1 1 1 1 1]) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
655 %!error <N must be positive> bitshift (10, [-2 -1 0 1 2], -1) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
656 */ |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
657 |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
658 DEFUN (flintmax, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
659 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
660 @deftypefn {} {} flintmax () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
661 @deftypefnx {} {} flintmax ("double") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
662 @deftypefnx {} {} flintmax ("single") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
663 Return the largest integer that can be represented consecutively in a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
664 floating point value. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
665 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
666 The default class is @qcode{"double"}, but @qcode{"single"} is a valid |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
667 option. On IEEE 754 compatible systems, @code{flintmax} is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
668 @w{@math{2^{53}}} for @qcode{"double"} and @w{@math{2^{24}}} for |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
669 @qcode{"single"}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
670 @seealso{intmax, realmax, realmin} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
671 @end deftypefn */) |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
672 { |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
673 int nargin = args.length (); |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
674 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
675 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
676 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
677 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
678 std::string cname = "double"; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
679 if (nargin == 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
680 cname = args(0).xstring_value ("flintmax: argument must be a string"); |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
681 |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
682 if (cname == "double") |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
683 return ovl (static_cast<double> (max_mantissa_value<double> () + 1)); |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
684 else if (cname == "single") |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
685 return ovl (static_cast<float> (max_mantissa_value<float> () + 1)); |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
686 else |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
687 error ("flintmax: not defined for class '%s'", cname.c_str ()); |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
688 } |
16939
06897f865f0b
Add flintmax() as an alias for function bitmax().
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
689 |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
690 /* |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
691 %!assert (flintmax (), 2^53) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
692 %!assert (flintmax ("double"), 2^53) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
693 %!assert (flintmax ("single"), single (2^24)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
694 |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
695 %!error flintmax (0) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
696 %!error flintmax ("double", 0) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
697 %!error flintmax ("int32") |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
698 %!error flintmax ("char") |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
699 */ |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
700 |
4915 | 701 DEFUN (intmax, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
702 doc: /* -*- texinfo -*- |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
703 @deftypefn {} {} intmax () |
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
704 @deftypefnx {} {} intmax ("@var{type}") |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
705 @deftypefnx {} {} intmax (@var{var}) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
706 Return the largest integer that can be represented by a specific integer type. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
707 |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
708 The input is either a string @qcode{"@var{type}"} specifying an integer type, |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
709 or it is an existing integer variable @var{var}. |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
710 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
711 Possible values for @var{type} are |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
712 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
713 @table @asis |
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
714 @item @qcode{"int8"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
715 signed 8-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
716 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
717 @item @qcode{"int16"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
718 signed 16-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
719 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
720 @item @qcode{"int32"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
721 signed 32-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
722 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
723 @item @qcode{"int64"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
724 signed 64-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
725 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
726 @item @qcode{"uint8"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
727 unsigned 8-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
728 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
729 @item @qcode{"uint16"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
730 unsigned 16-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
731 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
732 @item @qcode{"uint32"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
733 unsigned 32-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
734 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
735 @item @qcode{"uint64"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
736 unsigned 64-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
737 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
738 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
739 The default for @var{type} is @qcode{"int32"}. |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
740 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
741 Example Code - query an existing variable |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
742 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
743 @example |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
744 @group |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
745 x = int8 (1); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
746 intmax (x) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
747 @result{} 127 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
748 @end group |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
749 @end example |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
750 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
751 @seealso{intmin, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
752 @end deftypefn */) |
4908 | 753 { |
4915 | 754 int nargin = args.length (); |
755 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
756 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
757 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
758 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
759 std::string cname = "int32"; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
760 if (nargin == 1) |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
761 { |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
762 if (args(0).is_string ()) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
763 cname = args(0).string_value (); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
764 else if (args(0).isinteger ()) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
765 cname = args(0).class_name (); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
766 else |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
767 error ("intmax: argument must be a string or integer variable"); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
768 } |
4915 | 769 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
770 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
771 |
4915 | 772 if (cname == "uint8") |
5828 | 773 retval = octave_uint8 (std::numeric_limits<uint8_t>::max ()); |
4915 | 774 else if (cname == "uint16") |
5828 | 775 retval = octave_uint16 (std::numeric_limits<uint16_t>::max ()); |
4915 | 776 else if (cname == "uint32") |
5828 | 777 retval = octave_uint32 (std::numeric_limits<uint32_t>::max ()); |
4915 | 778 else if (cname == "uint64") |
5828 | 779 retval = octave_uint64 (std::numeric_limits<uint64_t>::max ()); |
4915 | 780 else if (cname == "int8") |
5828 | 781 retval = octave_int8 (std::numeric_limits<int8_t>::max ()); |
4915 | 782 else if (cname == "int16") |
5828 | 783 retval = octave_int16 (std::numeric_limits<int16_t>::max ()); |
4915 | 784 else if (cname == "int32") |
5828 | 785 retval = octave_int32 (std::numeric_limits<int32_t>::max ()); |
4915 | 786 else if (cname == "int64") |
5828 | 787 retval = octave_int64 (std::numeric_limits<int64_t>::max ()); |
4915 | 788 else |
789 error ("intmax: not defined for '%s' objects", cname.c_str ()); | |
790 | |
791 return retval; | |
792 } | |
793 | |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
794 /* |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
795 %!assert (intmax (), int32 (2^31 - 1)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
796 %!assert (intmax ("int8"), int8 (2^7 - 1)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
797 %!assert (intmax ("uint8"), uint8 (2^8 - 1)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
798 %!assert (intmax ("int16"), int16 (2^15 - 1)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
799 %!assert (intmax ("uint16"), uint16 (2^16 - 1)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
800 %!assert (intmax ("int32"), int32 (2^31 - 1)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
801 %!assert (intmax ("uint32"), uint32 (2^32 - 1)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
802 %!assert (intmax ("int64"), int64 (2^63 - 1)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
803 %!assert (intmax ("uint64"), uint64 (2^64 - 1)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
804 |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
805 %!test |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
806 %! x = int8 (1); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
807 %! assert (intmax (x), int8 (127)); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
808 |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
809 %!error intmax ("int32", 0) |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
810 %!error <must be a string or integer variable> intmax (1.0) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
811 %!error <not defined for 'double' objects> intmax ("double") |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
812 %!error <not defined for 'char' objects> intmax ("char") |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
813 */ |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
814 |
4915 | 815 DEFUN (intmin, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
816 doc: /* -*- texinfo -*- |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
817 @deftypefn {} {} intmin () |
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
818 @deftypefnx {} {} intmin ("@var{type}") |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
819 @deftypefnx {} {} intmin (@var{var}) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
820 Return the smallest integer that can be represented by a specific integer type. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
821 |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
822 The input is either a string @qcode{"@var{type}"} specifying an integer type, |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
823 or it is an existing integer variable @var{var}. |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
824 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
825 Possible values for @var{type} are |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
826 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
827 @table @asis |
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
828 @item @qcode{"int8"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
829 signed 8-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
830 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
831 @item @qcode{"int16"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
832 signed 16-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
833 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
834 @item @qcode{"int32"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
835 signed 32-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
836 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
837 @item @qcode{"int64"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
838 signed 64-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
839 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
840 @item @qcode{"uint8"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
841 unsigned 8-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
842 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
843 @item @qcode{"uint16"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
844 unsigned 16-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
845 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
846 @item @qcode{"uint32"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
847 unsigned 32-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
848 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
849 @item @qcode{"uint64"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
850 unsigned 64-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
851 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
852 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
853 The default for @var{type} is @qcode{"int32"}. |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
854 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
855 Example Code - query an existing variable |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
856 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
857 @example |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
858 @group |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
859 x = int8 (1); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
860 intmin (x) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
861 @result{} -128 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
862 @end group |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
863 @end example |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
864 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
865 @seealso{intmax, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
866 @end deftypefn */) |
4915 | 867 { |
868 int nargin = args.length (); | |
869 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
870 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
871 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
872 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
873 std::string cname = "int32"; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
874 if (nargin == 1) |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
875 { |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
876 if (args(0).is_string ()) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
877 cname = args(0).string_value (); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
878 else if (args(0).isinteger ()) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
879 cname = args(0).class_name (); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
880 else |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
881 error ("intmin: argument must be a string or integer variable"); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
882 } |
4915 | 883 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
884 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
885 |
4915 | 886 if (cname == "uint8") |
5828 | 887 retval = octave_uint8 (std::numeric_limits<uint8_t>::min ()); |
4915 | 888 else if (cname == "uint16") |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14725
diff
changeset
|
889 retval = octave_uint16 (std::numeric_limits<uint16_t>::min ()); |
4915 | 890 else if (cname == "uint32") |
5828 | 891 retval = octave_uint32 (std::numeric_limits<uint32_t>::min ()); |
4915 | 892 else if (cname == "uint64") |
5828 | 893 retval = octave_uint64 (std::numeric_limits<uint64_t>::min ()); |
4915 | 894 else if (cname == "int8") |
5828 | 895 retval = octave_int8 (std::numeric_limits<int8_t>::min ()); |
4915 | 896 else if (cname == "int16") |
5828 | 897 retval = octave_int16 (std::numeric_limits<int16_t>::min ()); |
4915 | 898 else if (cname == "int32") |
5828 | 899 retval = octave_int32 (std::numeric_limits<int32_t>::min ()); |
4915 | 900 else if (cname == "int64") |
5828 | 901 retval = octave_int64 (std::numeric_limits<int64_t>::min ()); |
4915 | 902 else |
903 error ("intmin: not defined for '%s' objects", cname.c_str ()); | |
904 | |
4908 | 905 return retval; |
906 } | |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
907 |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
908 /* |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
909 %!assert (intmin (), int32 (-2^31)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
910 %!assert (intmin ("int8"), int8 (-2^7)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
911 %!assert (intmin ("uint8"), uint8 (-2^8)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
912 %!assert (intmin ("int16"), int16 (-2^15)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
913 %!assert (intmin ("uint16"), uint16 (-2^16)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
914 %!assert (intmin ("int32"), int32 (-2^31)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
915 %!assert (intmin ("uint32"), uint32 (-2^32)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
916 %!assert (intmin ("int64"), int64 (-2^63)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
917 %!assert (intmin ("uint64"), uint64 (-2^64)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
918 |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
919 %!test |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
920 %! x = int8 (1); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
921 %! assert (intmin (x), int8 (-128)); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
922 |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
923 %!error intmin ("int32", 0) |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
924 %!error <must be a string or integer variable> intmin (1.0) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
925 %!error <not defined for 'double' objects> intmin ("double") |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
926 %!error <not defined for 'char' objects> intmin ("char") |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
927 */ |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
928 |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
929 DEFUN (sizemax, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
930 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
931 @deftypefn {} {} sizemax () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
932 Return the largest value allowed for the size of an array. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
933 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
934 If Octave is compiled with 64-bit indexing, the result is of class int64, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
935 otherwise it is of class int32. The maximum array size is slightly |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
936 smaller than the maximum value allowable for the relevant class as reported |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
937 by @code{intmax}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
938 @seealso{intmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
939 @end deftypefn */) |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
940 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
941 if (args.length () != 0) |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
942 print_usage (); |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
943 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
944 return octave_value (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
|
945 } |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
946 |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
947 /* |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
948 %!assert (sizemax () >= (intmax ("int32") - 1)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
949 |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
950 %!error sizemax (0) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
951 */ |