annotate src/bitfcns.cc @ 14846:460a3c6d8bf1

maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists. Example: func() => func () * dynamic.txi, func.txi, oop.txi, var.txi, embedded.cc, fortdemo.cc, funcdemo.cc, paramdemo.cc, stringdemo.cc, unwinddemo.cc, Array.cc, Array.h, CColVector.cc, CDiagMatrix.h, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc, CmplxGEPBAL.cc, EIG.cc, MSparse.cc, MatrixType.cc, Sparse-op-defs.h, Sparse-perm-op-defs.h, Sparse.cc, Sparse.h, SparseCmplxCHOL.cc, SparseCmplxCHOL.h, SparseCmplxLU.cc, SparseCmplxQR.cc, SparseCmplxQR.h, SparseQR.cc, SparseQR.h, SparsedbleCHOL.cc, SparsedbleCHOL.h, SparsedbleLU.cc, SparsedbleLU.h, base-lu.cc, cmd-hist.cc, dColVector.cc, dDiagMatrix.h, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, dbleCHOL.cc, dbleGEPBAL.cc, dim-vector.cc, eigs-base.cc, f2c-main.c, fCColVector.cc, fCDiagMatrix.h, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fCmplxGEPBAL.cc, fColVector.cc, fDiagMatrix.h, fEIG.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc, file-ops.cc, file-stat.cc, floatCHOL.cc, floatGEPBAL.cc, idx-vector.h, lo-specfun.cc, lo-sysdep.cc, mx-inlines.cc, oct-binmap.h, oct-convn.cc, oct-md5.cc, oct-mem.h, oct-rand.cc, oct-syscalls.cc, randgamma.c, randmtzig.c, sparse-base-chol.cc, sparse-base-chol.h, sparse-base-lu.cc, sparse-dmsolve.cc, tempname.c, curl.m, divergence.m, randi.m, dlmwrite.m, edit.m, getappdata.m, what.m, getarchdir.m, install.m, installed_packages.m, repackage.m, unload_packages.m, colorbar.m, figure.m, isosurface.m, legend.m, loglog.m, plot.m, plot3.m, plotyy.m, polar.m, __errplot__.m, __ghostscript__.m, __marching_cube__.m, __plt__.m, __scatter__.m, semilogx.m, semilogy.m, trimesh.m, trisurf.m, demo.m, test.m, datetick.m, __delaunayn__.cc, __dsearchn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, balance.cc, bsxfun.cc, ccolamd.cc, cellfun.cc, chol.cc, daspk.cc, dasrt.cc, dassl.cc, dmperm.cc, eig.cc, eigs.cc, fftw.cc, filter.cc, find.cc, kron.cc, lookup.cc, lsode.cc, matrix_type.cc, md5sum.cc, mgorth.cc, qr.cc, quad.cc, rand.cc, regexp.cc, symbfact.cc, tril.cc, urlwrite.cc, op-bm-bm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-cm-cm.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fdm-fdm.cc, op-fm-fm.cc, op-int.h, op-m-m.cc, op-m-scm.cc, op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-range.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-str.cc, op-struct.cc, bitfcns.cc, data.cc, debug.cc, dynamic-ld.cc, error.cc, gl-render.cc, graphics.cc, graphics.in.h, load-path.cc, ls-hdf5.cc, ls-mat5.cc, ls-mat5.h, ls-oct-ascii.cc, ls-oct-ascii.h, mex.cc, mk-errno-list, oct-map.cc, oct-obj.h, oct-parse.yy, octave-config.in.cc, ov-base-int.cc, ov-base-mat.cc, ov-base.cc, ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-cell.cc, ov-class.cc, ov-class.h, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-intx.h, ov-range.h, ov-re-mat.cc, ov-re-sparse.cc, ov-str-mat.cc, ov-struct.cc, ov-usr-fcn.h, ov.h, pr-output.cc, pt-id.cc, pt-id.h, pt-mat.cc, pt-select.cc, sparse.cc, symtab.cc, symtab.h, syscalls.cc, toplev.cc, txt-eng-ft.cc, variables.cc, zfstream.cc, zfstream.h, Dork.m, getStash.m, myStash.m, Gork.m, Pork.m, myStash.m, getStash.m, myStash.m, getStash.m, myStash.m, fntests.m: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
author Rik <octave@nomad.inbox5.com>
date Sun, 08 Jul 2012 11:28:50 -0700
parents fa48fd0f160f
children f7afecdd87ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
1 /*
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
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
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
4
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
6
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6678
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6678
diff changeset
10 option) any later version.
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
11
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
15 for more details.
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
16
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6678
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6678
diff changeset
19 <http://www.gnu.org/licenses/>.
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
20
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
21 */
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
22
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
25 #endif
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
26
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
27 #include "str-vec.h"
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
28 #include "quit.h"
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
29
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
30 #include "defun.h"
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
31 #include "error.h"
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
32 #include "ov.h"
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
33 #include "ov-uint64.h"
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
34 #include "ov-uint32.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
35 #include "ov-uint16.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
36 #include "ov-uint8.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
37 #include "ov-int64.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
38 #include "ov-int32.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
39 #include "ov-int16.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
40 #include "ov-int8.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
41 #include "ov-scalar.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
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
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
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
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
75 bitopxx(const OP& op, const std::string& fname,
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
76 const Array<T>& x, const Array<T>& y)
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++)
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
101 result(i+k) = op(x(i), y(k));
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
102 else
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
103 result(i) = op(x(i), y(i));
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
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
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
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
120 bitopx(const std::string& fname, const Array<T>& x, const Array<T>& y)
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
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
132 bitop(const std::string& fname, const octave_value_list& args)
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
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
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
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
313
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
314 DEFUN (bitand, args, ,
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
315 "-*- texinfo -*-\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
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
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8492
diff changeset
318 @var{x}, @var{y} must be in the range [0,bitmax]\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
319 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, bitmax}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
320 @end deftypefn")
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
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
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
323 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
324
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
325 DEFUN (bitor, args, ,
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
326 "-*- texinfo -*-\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
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
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8492
diff changeset
329 @var{x}, @var{y} must be in the range [0,bitmax]\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
330 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, bitmax}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
331 @end deftypefn")
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
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
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
334 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
335
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
336 DEFUN (bitxor, args, ,
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
337 "-*- texinfo -*-\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
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
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8492
diff changeset
340 @var{x}, @var{y} must be in the range [0,bitmax]\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
341 @seealso{bitand, bitor, bitset, bitget, bitcmp, bitshift, bitmax}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
342 @end deftypefn")
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
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
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
345 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
346
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
347 static int64_t
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
348 bitshift (double a, int n, int64_t mask)
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
349 {
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
350 // In the name of bug-for-bug compatibility.
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
351 if (a < 0)
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
352 return -bitshift (-a, n, mask);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
353
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
354 if (n > 0)
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
355 return (static_cast<int64_t> (a) << n) & mask;
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
356 else if (n < 0)
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
357 return (static_cast<int64_t> (a) >> -n) & mask;
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
358 else
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
359 return static_cast<int64_t> (a) & mask;
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
360 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
361
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
362 static int64_t
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
363 bitshift (float a, int n, int64_t mask)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
364 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
365 // In the name of bug-for-bug compatibility.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
366 if (a < 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
367 return -bitshift (-a, n, mask);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
368
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
369 if (n > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
370 return (static_cast<int64_t> (a) << n) & mask;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
371 else if (n < 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
372 return (static_cast<int64_t> (a) >> -n) & mask;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
373 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
374 return static_cast<int64_t> (a) & 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
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
377 // Note that the bitshift operators are undefined if shifted by more
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
378 // bits than in the type, so we need to test for the size of the
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
379 // shift.
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
380
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
381 #define DO_BITSHIFT(T) \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
382 if (! error_state) \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
383 { \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
384 double d1, d2; \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
385 \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
386 if (n.all_integers (d1, d2)) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
387 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
388 int m_nel = m.numel (); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
389 int n_nel = n.numel (); \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
390 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
391 bool is_scalar_op = (m_nel == 1 || n_nel == 1); \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
392 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
393 dim_vector m_dv = m.dims (); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
394 dim_vector n_dv = n.dims (); \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
395 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
396 bool is_array_op = (m_dv == n_dv); \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
397 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
398 if (is_array_op || is_scalar_op) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
399 { \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
400 T ## NDArray result; \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
401 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
402 if (m_nel != 1) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
403 result.resize (m_dv); \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
404 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
405 result.resize (n_dv); \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
406 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
407 for (int i = 0; i < m_nel; i++) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
408 if (is_scalar_op) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
409 for (int k = 0; k < n_nel; k++) \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
410 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
411 result(i+k) = 0; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
412 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
413 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
414 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
415 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
416 result(i) = 0; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
417 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
418 result(i) = bitshift (m(i), static_cast<int> (n(i)), mask); \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
419 \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
420 retval = result; \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
421 } \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
422 else \
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
423 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
424 } \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
425 else \
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
426 error ("bitshift: expecting integer as second argument"); \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
427 }
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
428
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
429 #define DO_UBITSHIFT(T, N) \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
430 do \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
431 { \
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
432 int bits_in_type = octave_ ## T :: nbits (); \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
433 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
434 octave_ ## T mask = octave_ ## T::max (); \
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
435 if ((N) < bits_in_type) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
436 mask = bitshift (mask, (N) - bits_in_type); \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
437 else if ((N) < 1) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
438 mask = 0; \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
439 DO_BITSHIFT (T); \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
440 } \
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
441 while (0)
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
442
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
443 #define DO_SBITSHIFT(T, N) \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
444 do \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
445 { \
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
446 int bits_in_type = octave_ ## T :: nbits (); \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
447 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
448 octave_ ## T mask = octave_ ## T::max (); \
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
449 if ((N) < bits_in_type) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
450 mask = bitshift (mask, (N) - bits_in_type); \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
451 else if ((N) < 1) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
452 mask = 0; \
9440
357cff83985d fix signed integer shift
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
453 mask = mask | octave_ ## T :: min (); /* FIXME: 2's complement only? */ \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
454 DO_BITSHIFT (T); \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
455 } \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
456 while (0)
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
457
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
458 DEFUN (bitshift, args, ,
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
459 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
460 @deftypefn {Built-in Function} {} bitshift (@var{a}, @var{k})\n\
6678
49724abe1236 [project @ 2007-05-31 19:44:45 by jwe]
jwe
parents: 6439
diff changeset
461 @deftypefnx {Built-in Function} {} bitshift (@var{a}, @var{k}, @var{n})\n\
8492
9e18aff77e9e [docs] remove
Brian Gough <bjg@gnu.org>
parents: 8347
diff changeset
462 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
463 integers in @var{a}. A positive @var{k} leads to a left shift;\n\
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
464 A negative value to a right shift. If @var{n} is omitted it defaults\n\
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
465 to log2(bitmax)+1.\n\
13922
6da23a2d7afc doc: Update bitshift() docstring
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
466 @var{n} must be in the range [1,log2(bitmax)+1] usually [1,33].\n\
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
467 \n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
468 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
469 @group\n\
7097
e8c94e473c68 [project @ 2007-11-02 17:24:23 by jwe]
jwe
parents: 7017
diff changeset
470 bitshift (eye (3), 1)\n\
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
471 @result{}\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
472 @group\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
473 2 0 0\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
474 0 2 0\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
475 0 0 2\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
476 @end group\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
477 \n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
478 bitshift (10, [-2, -1, 0, 1, 2])\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
479 @result{} 2 5 10 20 40\n\
6439
a37c427ae9d1 [project @ 2007-03-23 15:04:01 by jwe]
jwe
parents: 6108
diff changeset
480 @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
481 @c\n\
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
482 @c\n\
6439
a37c427ae9d1 [project @ 2007-03-23 15:04:01 by jwe]
jwe
parents: 6108
diff changeset
483 @c bitshift ([1, 10], 2, [3,4])\n\
a37c427ae9d1 [project @ 2007-03-23 15:04:01 by jwe]
jwe
parents: 6108
diff changeset
484 @c @result{} 4 8\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
485 @end group\n\
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
486 @end example\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
487 @seealso{bitand, bitor, bitxor, bitset, bitget, bitcmp, bitmax}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
488 @end deftypefn")
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
489 {
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
490 octave_value retval;
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
491
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
492 int nargin = args.length ();
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
493
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
494 if (nargin == 2 || nargin == 3)
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
495 {
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
496 int nbits = 64;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
497
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
498 NDArray n = args(1).array_value ();
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
499
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
500 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
501 error ("bitshift: expecting integer as second argument");
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
502 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
503 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
504 if (nargin == 3)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
505 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
506 // FIXME -- for compatibility, we should accept an array
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
507 // or a scalar as the third argument.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
508 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
509 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
510 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
511 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
512 nbits = args(2).int_value ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
513
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
514 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
515 error ("bitshift: N must be an integer");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
516 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
517 error ("bitshift: N must be positive");
10315
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
520 }
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
521
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
522 if (error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
523 return retval;
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
524
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
525 octave_value m_arg = args(0);
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
526 std::string cname = m_arg.class_name ();
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
527
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
528 if (cname == "uint8")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
529 DO_UBITSHIFT (uint8, nbits < 8 ? nbits : 8);
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
530 else if (cname == "uint16")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
531 DO_UBITSHIFT (uint16, nbits < 16 ? nbits : 16);
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
532 else if (cname == "uint32")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
533 DO_UBITSHIFT (uint32, nbits < 32 ? nbits : 32);
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
534 else if (cname == "uint64")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
535 DO_UBITSHIFT (uint64, nbits < 64 ? nbits : 64);
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
536 else if (cname == "int8")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
537 DO_SBITSHIFT (int8, nbits < 8 ? nbits : 8);
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
538 else if (cname == "int16")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
539 DO_SBITSHIFT (int16, nbits < 16 ? nbits : 16);
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
540 else if (cname == "int32")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
541 DO_SBITSHIFT (int32, nbits < 32 ? nbits : 32);
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
542 else if (cname == "int64")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
543 DO_SBITSHIFT (int64, nbits < 64 ? nbits : 64);
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
544 else if (cname == "double")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
545 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
546 nbits = (nbits < 53 ? nbits : 53);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
547 int64_t mask = 0x1FFFFFFFFFFFFFLL;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
548 if (nbits < 53)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
549 mask = mask >> (53 - nbits);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
550 else if (nbits < 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
551 mask = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
552 int bits_in_type = 64;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
553 NDArray m = m_arg.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
554 DO_BITSHIFT ( );
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
555 }
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
556 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
557 error ("bitshift: not defined for %s objects", cname.c_str ());
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
558 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
559 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
560 print_usage ();
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
561
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
562 return retval;
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
563 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
564
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
565 DEFUN (bitmax, args, ,
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
566 "-*- texinfo -*-\n\
10897
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
567 @deftypefn {Built-in Function} {} bitmax ()\n\
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
568 @deftypefnx {Built-in Function} {} bitmax (\"double\")\n\
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
569 @deftypefnx {Built-in Function} {} bitmax (\"single\")\n\
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
570 Return the largest integer that can be represented within a floating point\n\
12642
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
571 value. The default class is \"double\", but \"single\" is a valid option.\n\
10897
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
572 On IEEE-754 compatible systems, @code{bitmax} is @w{@math{2^{53} - 1}}.\n\
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
573 @end deftypefn")
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
574 {
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
575 octave_value retval;
10897
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
576 std::string cname = "double";
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
577 int nargin = args.length ();
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
578
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
579 if (nargin == 1 && args(0).is_string ())
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
580 cname = args(0).string_value ();
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
581 else if (nargin != 0)
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
582 {
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
583 print_usage ();
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
584 return retval;
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
585 }
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
586
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
587 if (cname == "double")
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
588 retval = (static_cast<double> (0x1FFFFFFFFFFFFFLL));
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
589 else if (cname == "single")
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
590 retval = (static_cast<double> (0xFFFFFFL));
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
591 else
10897
dbec9d590756 Add CLASS argument to bitmax
Rik <octave@nomad.inbox5.com>
parents: 10895
diff changeset
592 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
593
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
594 return retval;
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
595 }
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
596
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
597 DEFUN (intmax, args, ,
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
598 "-*- texinfo -*-\n\
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
599 @deftypefn {Built-in Function} {} intmax (@var{type})\n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
600 Return the largest integer that can be represented in an integer type.\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
601 The variable @var{type} can be\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
602 \n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
603 @table @code\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
604 @item int8\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
605 signed 8-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
606 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
607 @item int16\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
608 signed 16-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
609 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
610 @item int32\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
611 signed 32-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
612 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
613 @item int64\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
614 signed 64-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
615 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
616 @item uint8\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
617 unsigned 8-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
618 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
619 @item uint16\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
620 unsigned 16-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
621 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
622 @item uint32\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
623 unsigned 32-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
624 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
625 @item uint64\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
626 unsigned 64-bit integer.\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
627 @end table\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
628 \n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
629 The default for @var{type} is @code{uint32}.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
630 @seealso{intmin, bitmax}\n\
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
631 @end deftypefn")
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
632 {
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
633 octave_value retval;
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
634 std::string cname = "int32";
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
635 int nargin = args.length ();
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
636
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
637 if (nargin == 1 && args(0).is_string ())
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
638 cname = args(0).string_value ();
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
639 else if (nargin != 0)
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
640 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
641 print_usage ();
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
642 return retval;
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
643 }
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
644
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
645 if (cname == "uint8")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
646 retval = octave_uint8 (std::numeric_limits<uint8_t>::max ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
647 else if (cname == "uint16")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
648 retval = octave_uint16 (std::numeric_limits<uint16_t>::max ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
649 else if (cname == "uint32")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
650 retval = octave_uint32 (std::numeric_limits<uint32_t>::max ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
651 else if (cname == "uint64")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
652 retval = octave_uint64 (std::numeric_limits<uint64_t>::max ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
653 else if (cname == "int8")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
654 retval = octave_int8 (std::numeric_limits<int8_t>::max ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
655 else if (cname == "int16")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
656 retval = octave_int16 (std::numeric_limits<int16_t>::max ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
657 else if (cname == "int32")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
658 retval = octave_int32 (std::numeric_limits<int32_t>::max ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
659 else if (cname == "int64")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
660 retval = octave_int64 (std::numeric_limits<int64_t>::max ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
661 else
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
662 error ("intmax: not defined for '%s' objects", cname.c_str ());
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
663
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
664 return retval;
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
665 }
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
666
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
667 DEFUN (intmin, args, ,
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
668 "-*- texinfo -*-\n\
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
669 @deftypefn {Built-in Function} {} intmin (@var{type})\n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
670 Return the smallest integer that can be represented in an integer type.\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
671 The variable @var{type} can be\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
672 \n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
673 @table @code\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
674 @item int8\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
675 signed 8-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
676 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
677 @item int16\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
678 signed 16-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
679 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
680 @item int32\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
681 signed 32-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
682 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
683 @item int64\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
684 signed 64-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
685 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
686 @item uint8\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
687 unsigned 8-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
688 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
689 @item uint16\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
690 unsigned 16-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
691 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
692 @item uint32\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
693 unsigned 32-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
694 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
695 @item uint64\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
696 unsigned 64-bit integer.\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
697 @end table\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
698 \n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
699 The default for @var{type} is @code{uint32}.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
700 @seealso{intmax, bitmax}\n\
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
701 @end deftypefn")
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
702 {
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
703 octave_value retval;
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
704 std::string cname = "int32";
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
705 int nargin = args.length ();
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
706
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
707 if (nargin == 1 && args(0).is_string ())
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
708 cname = args(0).string_value ();
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
709 else if (nargin != 0)
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
710 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
711 print_usage ();
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
712 return retval;
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
713 }
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
714
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
715 if (cname == "uint8")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
716 retval = octave_uint8 (std::numeric_limits<uint8_t>::min ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
717 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
718 retval = octave_uint16 (std::numeric_limits<uint16_t>::min ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
719 else if (cname == "uint32")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
720 retval = octave_uint32 (std::numeric_limits<uint32_t>::min ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
721 else if (cname == "uint64")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
722 retval = octave_uint64 (std::numeric_limits<uint64_t>::min ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
723 else if (cname == "int8")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
724 retval = octave_int8 (std::numeric_limits<int8_t>::min ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
725 else if (cname == "int16")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
726 retval = octave_int16 (std::numeric_limits<int16_t>::min ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
727 else if (cname == "int32")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
728 retval = octave_int32 (std::numeric_limits<int32_t>::min ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
729 else if (cname == "int64")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
730 retval = octave_int64 (std::numeric_limits<int64_t>::min ());
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
731 else
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
732 error ("intmin: not defined for '%s' objects", cname.c_str ());
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
733
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
734 return retval;
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
735 }
10811
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
736
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
737 DEFUN (sizemax, args, ,
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
738 "-*- texinfo -*-\n\
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
739 @deftypefn {Built-in Function} {} sizemax ()\n\
10895
4176c5c62138 Imrove documentation string for sizemax
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
740 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
741 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
742 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
743 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
744 by @code{intmax}.\n\
10811
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
745 @seealso{intmax}\n\
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
746 @end deftypefn")
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
747 {
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
748 octave_value retval;
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
749
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
750 if (args.length () == 0)
10830
b4ebfd675321 avoid static initialization disaster in dim_vector
Jaroslav Hajek <highegg@gmail.com>
parents: 10811
diff changeset
751 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
752 else
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
753 print_usage ();
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
754
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
755 return retval;
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
756 }