Mercurial > octave
annotate libinterp/corefcn/bitfcns.cc @ 20804:a6eaedd8bd75
eliminate return statements after calls to print_usage
* bitfcns.cc, cellfun.cc, debug.cc, dirfns.cc, strfns.cc:
Eliminate return statements after calls to print_usage.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 04 Dec 2015 13:16:59 -0500 |
parents | f7084eae3318 |
children | 1142cf6abc0d |
rev | line source |
---|---|
4908 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19201
diff
changeset
|
3 Copyright (C) 2004-2015 John W. Eaton |
4908 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4908 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4908 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
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 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
91 octave_value retval; |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
92 if (is_array_op || is_scalar_op) |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
93 { |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
94 Array<T> result; |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
95 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
96 if (nelx != 1) |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
97 result.resize (dvx); |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
98 else |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
99 result.resize (dvy); |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
100 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
101 for (int i = 0; i < nelx; i++) |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
102 if (is_scalar_op) |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
103 for (int k = 0; k < nely; k++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
104 result(i+k) = op (x(i), y(k)); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
105 else |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
106 result(i) = op (x(i), y(i)); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
107 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
108 retval = result; |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
109 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
110 else |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
111 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
|
112 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
|
113 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
114 return retval; |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
115 } |
4908 | 116 |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
117 // Trampoline function, instantiates the proper template above, with |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
118 // reflective information hardwired. We can't hardwire this information |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
119 // 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
|
120 // information about which integer types we need to instantiate. |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
121 template<typename T> |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
122 octave_value |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
123 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
|
124 { |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
125 if (fname == "bitand") |
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_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
|
127 if (fname == "bitor") |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
128 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
|
129 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
130 //else (fname == "bitxor") |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
131 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
|
132 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
133 |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
134 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
|
135 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
|
136 { |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
137 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
|
138 && 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
|
139 && 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
|
140 } |
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 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
|
143 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
|
144 { |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
145 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
|
146 } |
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 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
|
149 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
|
150 { |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
151 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
|
152 } |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
153 |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
154 octave_value |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
155 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
|
156 { |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
157 octave_value retval; |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
158 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
159 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
160 print_usage (); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
161 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
162 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
|
163 || 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
|
164 || 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
|
165 || 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
|
166 || 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
|
167 || 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
|
168 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
169 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
|
170 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
|
171 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
172 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
|
173 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
|
174 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
175 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
|
176 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
|
177 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
178 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
|
179 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
180 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
|
181 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
182 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
|
183 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
|
184 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
185 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
|
186 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
187 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
|
188 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
189 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
|
190 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
|
191 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
192 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
|
193 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
194 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
|
195 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
196 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
|
197 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
|
198 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
199 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
|
200 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
201 else |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
202 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
203 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
|
204 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
|
205 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
206 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
|
207 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
|
208 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
209 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
|
210 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
211 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
212 else |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
213 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
214 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
|
215 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
|
216 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
217 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
|
218 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
219 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
|
220 || 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
|
221 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
222 uint64NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
223 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
|
224 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
225 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
226 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
227 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
|
228 || 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
|
229 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
230 uint32NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
231 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
|
232 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
233 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
|
234 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
235 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
|
236 || 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
|
237 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
238 uint16NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
239 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
|
240 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
241 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
|
242 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
243 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
|
244 || 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
|
245 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
246 uint8NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
247 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
|
248 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
249 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
|
250 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
251 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
|
252 || 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
|
253 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
254 int64NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
255 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
|
256 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
257 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
|
258 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
259 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
|
260 || 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
|
261 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
262 int32NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
263 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
|
264 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
265 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
|
266 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
267 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
|
268 || 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
|
269 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
270 int16NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
271 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
|
272 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
273 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
|
274 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
275 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
|
276 || 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
|
277 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
278 int8NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
279 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
|
280 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
281 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
|
282 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
283 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
|
284 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
|
285 } |
20804
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 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
|
288 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
289 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
|
290 || 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
|
291 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
292 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
|
293 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
|
294 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
295 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
296 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
297 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
|
298 || 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
|
299 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
300 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
|
301 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
|
302 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
303 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
304 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
305 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
|
306 || 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
|
307 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
308 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
|
309 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
|
310 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
311 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
312 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
313 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
|
314 || 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
|
315 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
316 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
|
317 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
|
318 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
319 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
320 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
321 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
|
322 || 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
|
323 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
324 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
|
325 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
|
326 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
327 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
328 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
329 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
|
330 || 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
|
331 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
332 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
|
333 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
|
334 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
335 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
336 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
337 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
|
338 || 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
|
339 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
340 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
|
341 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
|
342 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
343 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
344 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
345 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
|
346 || 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
|
347 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
348 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
|
349 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
|
350 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
351 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
352 } |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
353 else |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
354 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
|
355 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
356 else |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
357 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
|
358 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
359 return retval; |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
360 } |
4908 | 361 |
362 DEFUN (bitand, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
363 "-*- texinfo -*-\n\ |
4908 | 364 @deftypefn {Built-in Function} {} bitand (@var{x}, @var{y})\n\ |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
365 Return the bitwise AND of non-negative integers.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
366 \n\ |
20486 | 367 @var{x}, @var{y} must be in the range [0,intmax]\n\ |
368 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, intmax, flintmax}\n\ | |
5642 | 369 @end deftypefn") |
4908 | 370 { |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
371 return bitop ("bitand", args); |
4908 | 372 } |
373 | |
374 DEFUN (bitor, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
375 "-*- texinfo -*-\n\ |
4908 | 376 @deftypefn {Built-in Function} {} bitor (@var{x}, @var{y})\n\ |
20486 | 377 Return the bitwise OR of non-negative integers @var{x} and @var{y}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
378 \n\ |
20486 | 379 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, intmax, flintmax}\n\ |
5642 | 380 @end deftypefn") |
4908 | 381 { |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
382 return bitop ("bitor", args); |
4908 | 383 } |
384 | |
385 DEFUN (bitxor, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
386 "-*- texinfo -*-\n\ |
4908 | 387 @deftypefn {Built-in Function} {} bitxor (@var{x}, @var{y})\n\ |
20486 | 388 Return the bitwise XOR of non-negative integers @var{x} and @var{y}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
389 \n\ |
20486 | 390 @seealso{bitand, bitor, bitset, bitget, bitcmp, bitshift, intmax, flintmax}\n\ |
5642 | 391 @end deftypefn") |
4908 | 392 { |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
393 return bitop ("bitxor", args); |
4908 | 394 } |
395 | |
19146
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
396 /* |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
397 %!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
|
398 %!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
|
399 %!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
|
400 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
401 %!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
|
402 %!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
|
403 %!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
|
404 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
405 %!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
|
406 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
407 %!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
|
408 %!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
|
409 %!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
|
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 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
412 ## 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
|
413 %!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
|
414 %!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
|
415 */ |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
416 |
17389
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
417 template <typename T> |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
418 static int64_t |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
419 max_mantissa_value () |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
420 { |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
421 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
|
422 } |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
423 |
5828 | 424 static int64_t |
425 bitshift (double a, int n, int64_t mask) | |
4908 | 426 { |
6108 | 427 // In the name of bug-for-bug compatibility. |
428 if (a < 0) | |
429 return -bitshift (-a, n, mask); | |
430 | |
4915 | 431 if (n > 0) |
5828 | 432 return (static_cast<int64_t> (a) << n) & mask; |
4915 | 433 else if (n < 0) |
5828 | 434 return (static_cast<int64_t> (a) >> -n) & mask; |
4915 | 435 else |
5828 | 436 return static_cast<int64_t> (a) & mask; |
4908 | 437 } |
438 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
439 static int64_t |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
440 bitshift (float a, int n, int64_t mask) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
441 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
442 // In the name of bug-for-bug compatibility. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
443 if (a < 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
444 return -bitshift (-a, n, mask); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
445 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
446 if (n > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
447 return (static_cast<int64_t> (a) << n) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
448 else if (n < 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
449 return (static_cast<int64_t> (a) >> -n) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
450 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
451 return static_cast<int64_t> (a) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
452 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
453 |
4919 | 454 // Note that the bitshift operators are undefined if shifted by more |
455 // bits than in the type, so we need to test for the size of the | |
456 // shift. | |
457 | |
4908 | 458 #define DO_BITSHIFT(T) \ |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
459 double d1, d2; \ |
4908 | 460 \ |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
461 if (n.all_integers (d1, d2)) \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
462 { \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
463 int m_nel = m.numel (); \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
464 int n_nel = n.numel (); \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
465 \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
466 bool is_scalar_op = (m_nel == 1 || n_nel == 1); \ |
4908 | 467 \ |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
468 dim_vector m_dv = m.dims (); \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
469 dim_vector n_dv = n.dims (); \ |
4919 | 470 \ |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
471 bool is_array_op = (m_dv == n_dv); \ |
4908 | 472 \ |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
473 if (is_array_op || is_scalar_op) \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
474 { \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
475 T ## NDArray result; \ |
4908 | 476 \ |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
477 if (m_nel != 1) \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
478 result.resize (m_dv); \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
479 else \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
480 result.resize (n_dv); \ |
4908 | 481 \ |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
482 for (int i = 0; i < m_nel; i++) \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
483 if (is_scalar_op) \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
484 for (int k = 0; k < n_nel; k++) \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
485 if (static_cast<int> (n(k)) >= bits_in_type) \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
486 result(i+k) = 0; \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
487 else \ |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
488 result(i+k) = bitshift (m(i), static_cast<int> (n(k)), mask); \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
489 else \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
490 if (static_cast<int> (n(i)) >= bits_in_type) \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
491 result(i) = 0; \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
492 else \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
493 result(i) = bitshift (m(i), static_cast<int> (n(i)), mask); \ |
4908 | 494 \ |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
495 retval = result; \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
496 } \ |
4919 | 497 else \ |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
498 error ("bitshift: size of A and N must match, or one operand must be a scalar"); \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
499 } \ |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
500 else \ |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
501 error ("bitshift: K must be a scalar or array of integers"); \ |
4915 | 502 |
4919 | 503 #define DO_UBITSHIFT(T, N) \ |
504 do \ | |
505 { \ | |
4920 | 506 int bits_in_type = octave_ ## T :: nbits (); \ |
4919 | 507 T ## NDArray m = m_arg.T ## _array_value (); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
508 octave_ ## T mask = octave_ ## T::max (); \ |
4920 | 509 if ((N) < bits_in_type) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
510 mask = bitshift (mask, (N) - bits_in_type); \ |
4919 | 511 else if ((N) < 1) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
512 mask = 0; \ |
4919 | 513 DO_BITSHIFT (T); \ |
514 } \ | |
4915 | 515 while (0) |
516 | |
4919 | 517 #define DO_SBITSHIFT(T, N) \ |
518 do \ | |
519 { \ | |
4920 | 520 int bits_in_type = octave_ ## T :: nbits (); \ |
4919 | 521 T ## NDArray m = m_arg.T ## _array_value (); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
522 octave_ ## T mask = octave_ ## T::max (); \ |
4920 | 523 if ((N) < bits_in_type) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
524 mask = bitshift (mask, (N) - bits_in_type); \ |
4919 | 525 else if ((N) < 1) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
526 mask = 0; \ |
9440
357cff83985d
fix signed integer shift
Jaroslav Hajek <highegg@gmail.com>
parents:
9209
diff
changeset
|
527 mask = mask | octave_ ## T :: min (); /* FIXME: 2's complement only? */ \ |
4919 | 528 DO_BITSHIFT (T); \ |
529 } \ | |
4908 | 530 while (0) |
531 | |
532 DEFUN (bitshift, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
533 "-*- texinfo -*-\n\ |
10840 | 534 @deftypefn {Built-in Function} {} bitshift (@var{a}, @var{k})\n\ |
6678 | 535 @deftypefnx {Built-in Function} {} bitshift (@var{a}, @var{k}, @var{n})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
536 Return a @var{k} bit shift of @var{n}-digit unsigned integers in @var{a}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
537 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
538 A positive @var{k} leads to a left shift; A negative value to a right shift.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
539 \n\ |
20486 | 540 If @var{n} is omitted it defaults to 64.\n\ |
541 @var{n} must be in the range [1,64].\n\ | |
4908 | 542 \n\ |
543 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
544 @group\n\ |
7097 | 545 bitshift (eye (3), 1)\n\ |
4908 | 546 @result{}\n\ |
547 @group\n\ | |
548 2 0 0\n\ | |
549 0 2 0\n\ | |
550 0 0 2\n\ | |
551 @end group\n\ | |
552 \n\ | |
553 bitshift (10, [-2, -1, 0, 1, 2])\n\ | |
554 @result{} 2 5 10 20 40\n\ | |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
555 @c FIXME: restore this example when third arg is allowed to be an array.\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
556 @c\n\ |
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
557 @c\n\ |
6439 | 558 @c bitshift ([1, 10], 2, [3,4])\n\ |
559 @c @result{} 4 8\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
560 @end group\n\ |
4908 | 561 @end example\n\ |
20486 | 562 @seealso{bitand, bitor, bitxor, bitset, bitget, bitcmp, intmax, flintmax}\n\ |
5642 | 563 @end deftypefn") |
4908 | 564 { |
565 octave_value retval; | |
566 | |
567 int nargin = args.length (); | |
568 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
569 if (nargin < 2 || nargin > 3) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
570 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
571 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
572 int nbits = 64; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
573 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
574 NDArray n = args(1).xarray_value ("bitshift: K must be a scalar or array of integers"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
575 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
576 if (nargin == 3) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
577 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
578 // FIXME: for compatibility, we should accept an array |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
579 // or a scalar as the third argument. |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
580 if (args(2).numel () > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
581 error ("bitshift: N must be a scalar integer"); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
582 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
583 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
584 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
|
585 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
586 if (nbits < 0) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
587 error ("bitshift: N must be positive"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
588 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
589 } |
4915 | 590 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
591 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
|
592 std::string cname = m_arg.class_name (); |
4908 | 593 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
594 if (cname == "uint8") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
595 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
|
596 else if (cname == "uint16") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
597 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
|
598 else if (cname == "uint32") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
599 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
|
600 else if (cname == "uint64") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
601 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
|
602 else if (cname == "int8") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
603 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
|
604 else if (cname == "int16") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
605 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
|
606 else if (cname == "int32") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
607 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
|
608 else if (cname == "int64") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
609 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
|
610 else if (cname == "double") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
611 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
612 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
|
613 = std::numeric_limits<double>::digits; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
614 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
615 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
|
616 int64_t mask = max_mantissa_value<double> (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
617 if (nbits < bits_in_mantissa) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
618 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
|
619 else if (nbits < 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
620 mask = 0; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
621 int bits_in_type = sizeof (double) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
622 * std::numeric_limits<unsigned char>::digits; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
623 NDArray m = m_arg.array_value (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
624 DO_BITSHIFT (); |
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 else if (cname == "single") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
627 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
628 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
|
629 = std::numeric_limits<float>::digits; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
630 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
|
631 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
|
632 if (nbits < bits_in_mantissa) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
633 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
|
634 else if (nbits < 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
635 mask = 0; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
636 int bits_in_type = sizeof (float) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
637 * std::numeric_limits<unsigned char>::digits; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
638 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
|
639 DO_BITSHIFT (Float); |
4908 | 640 } |
641 else | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
642 error ("bitshift: not defined for %s objects", cname.c_str ()); |
4908 | 643 |
644 return retval; | |
645 } | |
646 | |
19146
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
647 /* |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
648 %!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
|
649 %!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
|
650 %!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
|
651 %!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
|
652 %!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
|
653 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
654 %!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
|
655 %!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
|
656 %!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
|
657 %!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
|
658 */ |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
659 |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
660 DEFUN (flintmax, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
661 "-*- texinfo -*-\n\ |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
662 @deftypefn {Built-in Function} {} flintmax ()\n\ |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
663 @deftypefnx {Built-in Function} {} flintmax (\"double\")\n\ |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
664 @deftypefnx {Built-in Function} {} flintmax (\"single\")\n\ |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
665 Return the largest integer that can be represented consecutively in a\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
666 floating point value.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
667 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
668 The default class is @qcode{\"double\"}, but @qcode{\"single\"} is a valid\n\ |
20425
6947b9c82d4b
doc: Change docstrings to use 'IEEE 754' rather than 'IEEE-754'.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
669 option. On IEEE 754 compatible systems, @code{flintmax} is @w{@math{2^{53}}}\n\ |
6947b9c82d4b
doc: Change docstrings to use 'IEEE 754' rather than 'IEEE-754'.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
670 for @qcode{\"double\"} and @w{@math{2^{24}}} for @qcode{\"single\"}.\n\ |
20486 | 671 @seealso{intmax, realmax, realmin}\n\ |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
672 @end deftypefn") |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
673 { |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
674 octave_value retval; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
675 |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
676 std::string cname = "double"; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
677 |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
678 int nargin = args.length (); |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
679 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
680 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
681 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
682 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
683 if (nargin == 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
684 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
|
685 |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
686 if (cname == "double") |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
687 retval = (static_cast<double> (max_mantissa_value<double> () + 1)); |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
688 else if (cname == "single") |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
689 retval = (static_cast<float> (max_mantissa_value<float> () + 1)); |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
690 else |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
691 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
|
692 |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
693 return retval; |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
694 } |
16939
06897f865f0b
Add flintmax() as an alias for function bitmax().
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
695 |
4915 | 696 DEFUN (intmax, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
697 "-*- texinfo -*-\n\ |
4915 | 698 @deftypefn {Built-in Function} {} intmax (@var{type})\n\ |
5040 | 699 Return the largest integer that can be represented in an integer type.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
700 \n\ |
5040 | 701 The variable @var{type} can be\n\ |
702 \n\ | |
703 @table @code\n\ | |
704 @item int8\n\ | |
705 signed 8-bit integer.\n\ | |
10840 | 706 \n\ |
5040 | 707 @item int16\n\ |
708 signed 16-bit integer.\n\ | |
10840 | 709 \n\ |
5040 | 710 @item int32\n\ |
711 signed 32-bit integer.\n\ | |
10840 | 712 \n\ |
5040 | 713 @item int64\n\ |
714 signed 64-bit integer.\n\ | |
10840 | 715 \n\ |
5040 | 716 @item uint8\n\ |
717 unsigned 8-bit integer.\n\ | |
10840 | 718 \n\ |
5040 | 719 @item uint16\n\ |
720 unsigned 16-bit integer.\n\ | |
10840 | 721 \n\ |
5040 | 722 @item uint32\n\ |
723 unsigned 32-bit integer.\n\ | |
10840 | 724 \n\ |
5040 | 725 @item uint64\n\ |
726 unsigned 64-bit integer.\n\ | |
727 @end table\n\ | |
728 \n\ | |
18155
20f2b3c48c4c
intmax, intmin: Fix default integer type in docstrings
Mike Miller <mtmiller@ieee.org>
parents:
17861
diff
changeset
|
729 The default for @var{type} is @code{int32}.\n\ |
20486 | 730 @seealso{intmin, flintmax}\n\ |
4908 | 731 @end deftypefn") |
732 { | |
733 octave_value retval; | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
734 |
4915 | 735 std::string cname = "int32"; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
736 |
4915 | 737 int nargin = args.length (); |
738 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
739 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
740 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
741 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
742 if (nargin == 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
743 cname = args(0).xstring_value ("intmax: argument must be a string"); |
4915 | 744 |
745 if (cname == "uint8") | |
5828 | 746 retval = octave_uint8 (std::numeric_limits<uint8_t>::max ()); |
4915 | 747 else if (cname == "uint16") |
5828 | 748 retval = octave_uint16 (std::numeric_limits<uint16_t>::max ()); |
4915 | 749 else if (cname == "uint32") |
5828 | 750 retval = octave_uint32 (std::numeric_limits<uint32_t>::max ()); |
4915 | 751 else if (cname == "uint64") |
5828 | 752 retval = octave_uint64 (std::numeric_limits<uint64_t>::max ()); |
4915 | 753 else if (cname == "int8") |
5828 | 754 retval = octave_int8 (std::numeric_limits<int8_t>::max ()); |
4915 | 755 else if (cname == "int16") |
5828 | 756 retval = octave_int16 (std::numeric_limits<int16_t>::max ()); |
4915 | 757 else if (cname == "int32") |
5828 | 758 retval = octave_int32 (std::numeric_limits<int32_t>::max ()); |
4915 | 759 else if (cname == "int64") |
5828 | 760 retval = octave_int64 (std::numeric_limits<int64_t>::max ()); |
4915 | 761 else |
762 error ("intmax: not defined for '%s' objects", cname.c_str ()); | |
763 | |
764 return retval; | |
765 } | |
766 | |
767 DEFUN (intmin, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
768 "-*- texinfo -*-\n\ |
4915 | 769 @deftypefn {Built-in Function} {} intmin (@var{type})\n\ |
5040 | 770 Return the smallest integer that can be represented in an integer type.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
771 \n\ |
5040 | 772 The variable @var{type} can be\n\ |
773 \n\ | |
774 @table @code\n\ | |
775 @item int8\n\ | |
776 signed 8-bit integer.\n\ | |
10840 | 777 \n\ |
5040 | 778 @item int16\n\ |
779 signed 16-bit integer.\n\ | |
10840 | 780 \n\ |
5040 | 781 @item int32\n\ |
782 signed 32-bit integer.\n\ | |
10840 | 783 \n\ |
5040 | 784 @item int64\n\ |
785 signed 64-bit integer.\n\ | |
10840 | 786 \n\ |
5040 | 787 @item uint8\n\ |
788 unsigned 8-bit integer.\n\ | |
10840 | 789 \n\ |
5040 | 790 @item uint16\n\ |
791 unsigned 16-bit integer.\n\ | |
10840 | 792 \n\ |
5040 | 793 @item uint32\n\ |
794 unsigned 32-bit integer.\n\ | |
10840 | 795 \n\ |
5040 | 796 @item uint64\n\ |
797 unsigned 64-bit integer.\n\ | |
798 @end table\n\ | |
799 \n\ | |
18155
20f2b3c48c4c
intmax, intmin: Fix default integer type in docstrings
Mike Miller <mtmiller@ieee.org>
parents:
17861
diff
changeset
|
800 The default for @var{type} is @code{int32}.\n\ |
20486 | 801 @seealso{intmax, flintmax}\n\ |
4915 | 802 @end deftypefn") |
803 { | |
804 octave_value retval; | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
805 |
4915 | 806 std::string cname = "int32"; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
807 |
4915 | 808 int nargin = args.length (); |
809 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
810 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
811 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
812 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
813 if (nargin == 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
814 cname = args(0).xstring_value ("intmin: argument must be a string"); |
4915 | 815 |
816 if (cname == "uint8") | |
5828 | 817 retval = octave_uint8 (std::numeric_limits<uint8_t>::min ()); |
4915 | 818 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
|
819 retval = octave_uint16 (std::numeric_limits<uint16_t>::min ()); |
4915 | 820 else if (cname == "uint32") |
5828 | 821 retval = octave_uint32 (std::numeric_limits<uint32_t>::min ()); |
4915 | 822 else if (cname == "uint64") |
5828 | 823 retval = octave_uint64 (std::numeric_limits<uint64_t>::min ()); |
4915 | 824 else if (cname == "int8") |
5828 | 825 retval = octave_int8 (std::numeric_limits<int8_t>::min ()); |
4915 | 826 else if (cname == "int16") |
5828 | 827 retval = octave_int16 (std::numeric_limits<int16_t>::min ()); |
4915 | 828 else if (cname == "int32") |
5828 | 829 retval = octave_int32 (std::numeric_limits<int32_t>::min ()); |
4915 | 830 else if (cname == "int64") |
5828 | 831 retval = octave_int64 (std::numeric_limits<int64_t>::min ()); |
4915 | 832 else |
833 error ("intmin: not defined for '%s' objects", cname.c_str ()); | |
834 | |
4908 | 835 return retval; |
836 } | |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
837 |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
838 DEFUN (sizemax, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
839 "-*- texinfo -*-\n\ |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
840 @deftypefn {Built-in Function} {} sizemax ()\n\ |
10895
4176c5c62138
Imrove documentation string for sizemax
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
841 Return the largest value allowed for the size of an array.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
842 \n\ |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
843 If Octave is compiled with 64-bit indexing, the result is of class int64,\n\ |
10895
4176c5c62138
Imrove documentation string for sizemax
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
844 otherwise it is of class int32. The maximum array size is slightly\n\ |
4176c5c62138
Imrove documentation string for sizemax
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
845 smaller than the maximum value allowable for the relevant class as reported\n\ |
4176c5c62138
Imrove documentation string for sizemax
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
846 by @code{intmax}.\n\ |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
847 @seealso{intmax}\n\ |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
848 @end deftypefn") |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
849 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
850 if (args.length () != 0) |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
851 print_usage (); |
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
852 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
853 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
|
854 } |