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