annotate libinterp/corefcn/bitfcns.cc @ 21724:aba2e6293dd8

use "#if ..." consistently instead of "#ifdef" and "#ifndef" * configure.ac, Doxyfile.in, make_int.cc, Backend.cc, BaseControl.cc, ButtonControl.cc, Canvas.cc, CheckBoxControl.cc, Container.cc, ContextMenu.cc, EditControl.cc, Figure.cc, FigureWindow.cc, GLCanvas.cc, KeyMap.cc, ListBoxControl.cc, Logger.cc, Menu.cc, MouseModeActionGroup.cc, Object.cc, ObjectFactory.cc, ObjectProxy.cc, Panel.cc, PopupMenuControl.cc, PushButtonControl.cc, PushTool.cc, QtHandlesUtils.cc, RadioButtonControl.cc, SliderControl.cc, TextControl.cc, TextEdit.cc, ToggleButtonControl.cc, ToggleTool.cc, ToolBar.cc, __init_qt__.cc, annotation-dialog.cc, gl-select.cc, module.mk, color-picker.cc, dialog.cc, documentation-dock-widget.cc, files-dock-widget.cc, find-files-dialog.cc, find-files-model.cc, history-dock-widget.cc, liboctgui-build-info.in.cc, file-editor-tab.cc, file-editor.cc, find-dialog.cc, marker.cc, marker.h, octave-qscintilla.cc, octave-txt-lexer.cc, main-window.cc, octave-cmd.cc, octave-dock-widget.cc, octave-gui.cc, octave-interpreter.cc, octave-qt-link.cc, parser.cc, webinfo.cc, resource-manager.cc, settings-dialog.cc, shortcut-manager.cc, terminal-dock-widget.cc, thread-manager.cc, welcome-wizard.cc, workspace-model.cc, workspace-view.cc, build-env.in.cc, Cell.cc, __contourc__.cc, __dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __ilu__.cc, __lin_interpn__.cc, __luinc__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, cdisplay.c, cdisplay.h, cellfun.cc, coct-hdf5-types.c, colloc.cc, comment-list.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, defaults.cc, defaults.in.h, defun.cc, det.cc, dirfns.cc, display.cc, dlmread.cc, dot.cc, dynamic-ld.cc, eig.cc, ellipj.cc, error.cc, errwarn.cc, event-queue.cc, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl2ps-print.cc, graphics.cc, gripes.cc, hash.cc, help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, jit-ir.cc, jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, jit-util.cc, jit-util.h, kron.cc, load-path.cc, load-save.cc, lookup.cc, ls-ascii-helper.cc, ls-hdf5.cc, ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc, ls-oct-text.h, ls-utils.cc, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex.cc, mex.h, mexproto.h, mgorth.cc, nproc.cc, oct-errno.in.cc, oct-fstrm.cc, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-iostrm.cc, oct-lvalue.cc, oct-map.cc, oct-prcstrm.cc, oct-procbuf.cc, oct-stdstrm.h, oct-stream.cc, oct-strstrm.cc, oct-tex-lexer.in.ll, oct-tex-parser.in.yy, octave-link.cc, ordschur.cc, pager.cc, pinv.cc, pr-output.cc, procstream.cc, profiler.cc, psi.cc, pt-jit.cc, pt-jit.h, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sighandlers.h, siglist.c, siglist.h, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, text-renderer.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, txt-eng.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc, xdiv.cc, xgl2ps.c, xnorm.cc, xpow.cc, zfstream.cc, zfstream.h, __delaunayn__.cc, __eigs__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc, audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc, convhulln.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc, liboctinterp-build-info.in.cc, mkbuiltins, mkops, ov-base.cc, ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc, ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-classdef.cc, ov-colon.cc, ov-complex.cc, ov-cs-list.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-fcn.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-int16.cc, ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.cc, ov-lazy-idx.cc, ov-mex-fcn.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ovl.cc, octave.cc, octave.h, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cdm-cm.cc, op-cdm-dm.cc, op-cdm-m.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cdm.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-dm.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-cdm.cc, op-dm-cm.cc, op-dm-dm.cc, op-dm-m.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-double-conv.cc, op-fcdm-fcdm.cc, op-fcdm-fcm.cc, op-fcdm-fdm.cc, op-fcdm-fm.cc, op-fcm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fdm.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fcdm.cc, op-fdm-fcm.cc, op-fdm-fdm.cc, op-fdm-fm.cc, op-float-conv.cc, op-fm-fcdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fdm.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-int-conv.cc, op-m-cdm.cc, op-m-cm.cc, op-m-cs.cc, op-m-dm.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.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-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, lex.ll, oct-parse.in.yy, pt-arg-list.cc, pt-array-list.cc, pt-assign.cc, pt-binop.cc, pt-bp.cc, pt-cbinop.cc, pt-cell.cc, pt-check.cc, pt-classdef.cc, pt-cmd.cc, pt-colon.cc, pt-const.cc, pt-decl.cc, pt-eval.cc, pt-except.cc, pt-exp.cc, pt-fcn-handle.cc, pt-funcall.cc, pt-id.cc, pt-idx.cc, pt-jump.cc, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-misc.cc, pt-pr-code.cc, pt-select.cc, pt-stmt.cc, pt-unop.cc, pt.cc, token.cc, Array-jit.cc, Array-tc.cc, version.cc, Array-C.cc, Array-b.cc, Array-ch.cc, Array-d.cc, Array-f.cc, Array-fC.cc, Array-i.cc, Array-idx-vec.cc, Array-s.cc, Array-str.cc, Array-util.cc, Array-voidp.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc, MArray-C.cc, MArray-d.cc, MArray-f.cc, MArray-fC.cc, MArray-i.cc, MArray-s.cc, MSparse-C.cc, MSparse-d.cc, MatrixType.cc, PermMatrix.cc, Range.cc, Sparse-C.cc, Sparse-b.cc, Sparse-d.cc, boolMatrix.cc, boolNDArray.cc, boolSparse.cc, chMatrix.cc, chNDArray.cc, dColVector.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, dim-vector.cc, dim-vector.h, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc, int16NDArray.cc, int32NDArray.cc, int64NDArray.cc, int8NDArray.cc, uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc, uint8NDArray.cc, Faddeeva.cc, blaswrap.c, cquit.c, f77-extern.cc, f77-fcn.c, f77-fcn.h, lo-error.c, lo-error.h, quit.cc, quit.h, liboctave-build-info.in.cc, CollocWt.cc, DASPK.cc, DASRT.cc, DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, aepbalance.cc, chol.cc, eigs-base.cc, fEIG.cc, gepbalance.cc, hess.cc, lo-mappers.cc, lo-specfun.cc, lu.cc, oct-convn.cc, oct-fftw.cc, oct-norm.cc, oct-rand.cc, oct-spparms.cc, qr.cc, qrp.cc, randmtzig.cc, randpoisson.cc, schur.cc, sparse-chol.cc, sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, svd.cc, mk-ops.awk, mx-defs.h, dir-ops.cc, file-ops.cc, file-stat.cc, lo-sysdep.cc, mach-info.cc, oct-env.cc, oct-group.cc, oct-passwd.cc, oct-syscalls.cc, oct-time.cc, oct-uname.cc, pathlen.h, syswait.h, cmd-edit.cc, cmd-hist.cc, data-conv.cc, f2c-main.c, glob-match.cc, kpse.cc, lo-array-errwarn.cc, lo-array-gripes.cc, lo-cutils.c, lo-cutils.h, lo-ieee.cc, lo-ieee.h, lo-regexp.cc, lo-utils.cc, oct-base64.cc, oct-glob.cc, oct-inttypes.cc, oct-inttypes.h, oct-locbuf.cc, oct-mutex.cc, oct-rl-edit.c, oct-rl-edit.h, oct-rl-hist.c, oct-rl-hist.h, oct-shlib.cc, oct-sort.cc, pathsearch.cc, singleton-cleanup.cc, sparse-sort.cc, sparse-util.cc, statdefs.h, str-vec.cc, unwind-prot.cc, url-transfer.cc, acinclude.m4, display-available.c, display-available.h, main-cli.cc, main-gui.cc, main.in.cc, mkoctfile.in.cc, octave-build-info.in.cc, octave-config.in.cc, shared-fcns.h: Use "#if ..." consistently instead of "#ifdef" and "#ifndef".
author John W. Eaton <jwe@octave.org>
date Tue, 17 May 2016 12:09:30 -0400
parents 3d60ed163b70
children b571fc85953f
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
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19201
diff changeset
3 Copyright (C) 2004-2015 John W. Eaton
4908
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
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21568
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
24 # include "config.h"
4908
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
17396
0b644adf4f31 speak CHAR_BIT in C++-ese
John W. Eaton <jwe@octave.org>
parents: 17392
diff changeset
27 #include <limits>
0b644adf4f31 speak CHAR_BIT in C++-ese
John W. Eaton <jwe@octave.org>
parents: 17392
diff changeset
28
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
29 #include "str-vec.h"
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
30 #include "quit.h"
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
31
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
32 #include "defun.h"
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
33 #include "error.h"
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
34 #include "ov.h"
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
35 #include "ov-uint64.h"
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
36 #include "ov-uint32.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
37 #include "ov-uint16.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
38 #include "ov-uint8.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
39 #include "ov-int64.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
40 #include "ov-int32.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
41 #include "ov-int16.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
42 #include "ov-int8.h"
17392
e09cd91168d1 Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents: 17390
diff changeset
43 #include "ov-float.h"
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
44 #include "ov-scalar.h"
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
45 #include "ov-re-mat.h"
7763
0c6b4c7d7117 Treat bool as a scalar in the bit functions
David Bateman <dbateman@free.fr>
parents: 7097
diff changeset
46 #include "ov-bool.h"
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
47
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
48 #include <functional>
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
49
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20711
diff changeset
50 #if ! defined (HAVE_CXX_BITWISE_OP_TEMPLATES)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
51 namespace std
14725
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
52 {
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
53 template <typename T>
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
54 struct bit_and
14725
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
55 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
56 public:
14725
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
57 T operator() (const T & op1, const T & op2) const { return (op1 & op2); }
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
58 };
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
59
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
60 template <typename T>
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
61 struct bit_or
14725
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
62 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
63 public:
14725
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
64 T operator() (const T & op1, const T & op2) const { return (op1 | op2); }
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
65 };
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
66
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
67 template <typename T>
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
68 struct bit_xor
14725
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
69 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
70 public:
14725
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
71 T operator() (const T & op1, const T & op2) const { return (op1 ^ op2); }
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
72 };
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
73 }
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
74 #endif
fa48fd0f160f Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14631
diff changeset
75
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
76 template <typename OP, typename T>
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
77 octave_value
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
78 bitopxx (const OP& op, const std::string& fname,
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
79 const Array<T>& x, const Array<T>& y)
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
80 {
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
81 int nelx = x.numel ();
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
82 int nely = y.numel ();
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
83
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
84 bool is_scalar_op = (nelx == 1 || nely == 1);
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
85
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
86 dim_vector dvx = x.dims ();
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
87 dim_vector dvy = y.dims ();
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
88
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
89 bool is_array_op = (dvx == dvy);
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
90
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
91 if (! is_array_op && ! is_scalar_op)
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
92 error ("%s: size of X and Y must match, or one operand must be a scalar",
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14725
diff changeset
93 fname.c_str ());
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
94
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
95 Array<T> result;
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
96
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
97 if (nelx != 1)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
98 result.resize (dvx);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
99 else
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
100 result.resize (dvy);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
101
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
102 for (int i = 0; i < nelx; i++)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
103 if (is_scalar_op)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
104 for (int k = 0; k < nely; k++)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
105 result(i+k) = op (x(i), y(k));
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
106 else
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
107 result(i) = op (x(i), y(i));
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
108
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
109 return result;
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
110 }
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
111
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
112 // Trampoline function, instantiates the proper template above, with
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
113 // 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
114 // in Fbitxxx DEFUNs below, because at that moment, we still don't have
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
115 // information about which integer types we need to instantiate.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20980
diff changeset
116 template <typename T>
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
117 octave_value
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
118 bitopx (const std::string& fname, const Array<T>& x, const Array<T>& y)
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
119 {
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
120 if (fname == "bitand")
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
121 return bitopxx (std::bit_and<T>(), fname, x, y);
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
122 if (fname == "bitor")
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
123 return bitopxx (std::bit_or<T>(), fname, x, y);
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
124
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
125 //else (fname == "bitxor")
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
126 return bitopxx (std::bit_xor<T>(), fname, x, y);
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
127 }
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
128
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
129 static inline int
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
130 bitop_arg_is_int (const octave_value& arg)
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
131 {
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
132 return (arg.class_name () != octave_scalar::static_class_name ()
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
133 && arg.class_name () != octave_float_scalar::static_class_name ()
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
134 && arg.class_name () != octave_bool::static_class_name ());
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
135 }
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
136
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
137 static inline int
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
138 bitop_arg_is_bool (const octave_value& arg)
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
139 {
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
140 return arg.class_name () == octave_bool::static_class_name ();
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
141 }
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
142
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
143 static inline int
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
144 bitop_arg_is_float (const octave_value& arg)
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
145 {
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
146 return arg.class_name () == octave_float_scalar::static_class_name ();
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
147 }
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
148
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
149 octave_value
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
150 bitop (const std::string& fname, const octave_value_list& args)
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
151 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
152 if (args.length () != 2)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
153 print_usage ();
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
154
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
155 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
156
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
157 if (args(0).class_name () == octave_scalar::static_class_name ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
158 || args(0).class_name () == octave_float_scalar::static_class_name ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
159 || args(0).class_name () == octave_bool::static_class_name ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
160 || args(1).class_name () == octave_scalar::static_class_name ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
161 || args(1).class_name () == octave_float_scalar::static_class_name ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
162 || args(1).class_name () == octave_bool::static_class_name ())
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
163 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
164 bool arg0_is_int = bitop_arg_is_int (args(0));
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
165 bool arg1_is_int = bitop_arg_is_int (args(1));
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
166
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
167 bool arg0_is_bool = bitop_arg_is_bool (args(0));
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
168 bool arg1_is_bool = bitop_arg_is_bool (args(1));
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
169
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
170 bool arg0_is_float = bitop_arg_is_float (args(0));
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
171 bool arg1_is_float = bitop_arg_is_float (args(1));
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
172
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
173 if (! (arg0_is_int || arg1_is_int))
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
174 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
175 if (arg0_is_bool && arg1_is_bool)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
176 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
177 boolNDArray x (args(0).bool_array_value ());
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
178 boolNDArray y (args(1).bool_array_value ());
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
179
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
180 retval = bitopx (fname, x, y).bool_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
181 }
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
182 else if (arg0_is_float && arg1_is_float)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
183 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
184 uint64NDArray x (args(0).float_array_value ());
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
185 uint64NDArray y (args(1).float_array_value ());
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
186
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
187 retval = bitopx (fname, x, y).float_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
188 }
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
189 else if (! (arg0_is_float || arg1_is_float))
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
190 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
191 uint64NDArray x (args(0).array_value ());
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
192 uint64NDArray y (args(1).array_value ());
17392
e09cd91168d1 Support arguments of class single in bit manipulation functions (bug #34502)
Mike Miller <mtmiller@ieee.org>
parents: 17390
diff changeset
193
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
194 retval = bitopx (fname, x, y).array_value ();
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
195 }
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
196 else
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
197 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
198 int p = (arg0_is_float ? 1 : 0);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
199 int q = (arg0_is_float ? 0 : 1);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
200
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
201 uint64NDArray x (args(p).array_value ());
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
202 uint64NDArray y (args(q).float_array_value ());
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
203
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
204 retval = bitopx (fname, x, y).float_array_value ();
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
205 }
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
206 }
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
207 else
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
208 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
209 int p = (arg0_is_int ? 1 : 0);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
210 int q = (arg0_is_int ? 0 : 1);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
211
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
212 NDArray dx = args(p).array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
213
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
214 if (args(q).type_id () == octave_uint64_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
215 || args(q).type_id () == octave_uint64_scalar::static_type_id ())
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
216 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
217 uint64NDArray x (dx);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
218 uint64NDArray y = args(q).uint64_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
219
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
220 retval = bitopx (fname, x, y);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
221 }
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
222 else if (args(q).type_id () == octave_uint32_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
223 || args(q).type_id () == octave_uint32_scalar::static_type_id ())
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
224 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
225 uint32NDArray x (dx);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
226 uint32NDArray y = args(q).uint32_array_value ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
227
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
228 retval = bitopx (fname, x, y);
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
229 }
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
230 else if (args(q).type_id () == octave_uint16_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
231 || args(q).type_id () == octave_uint16_scalar::static_type_id ())
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
232 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
233 uint16NDArray x (dx);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
234 uint16NDArray y = args(q).uint16_array_value ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
235
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
236 retval = bitopx (fname, x, y);
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
237 }
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
238 else if (args(q).type_id () == octave_uint8_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
239 || args(q).type_id () == octave_uint8_scalar::static_type_id ())
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
240 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
241 uint8NDArray x (dx);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
242 uint8NDArray y = args(q).uint8_array_value ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
243
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
244 retval = bitopx (fname, x, y);
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
245 }
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
246 else if (args(q).type_id () == octave_int64_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
247 || args(q).type_id () == octave_int64_scalar::static_type_id ())
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
248 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
249 int64NDArray x (dx);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
250 int64NDArray y = args(q).int64_array_value ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
251
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
252 retval = bitopx (fname, x, y);
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
253 }
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
254 else if (args(q).type_id () == octave_int32_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
255 || args(q).type_id () == octave_int32_scalar::static_type_id ())
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
256 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
257 int32NDArray x (dx);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
258 int32NDArray y = args(q).int32_array_value ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
259
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
260 retval = bitopx (fname, x, y);
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
261 }
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
262 else if (args(q).type_id () == octave_int16_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
263 || args(q).type_id () == octave_int16_scalar::static_type_id ())
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
264 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
265 int16NDArray x (dx);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
266 int16NDArray y = args(q).int16_array_value ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
267
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21547
diff changeset
268 retval = bitopx (fname, x, y);
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
269 }
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
270 else if (args(q).type_id () == octave_int8_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
271 || args(q).type_id () == octave_int8_scalar::static_type_id ())
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
272 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
273 int8NDArray x (dx);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
274 int8NDArray y = args(q).int8_array_value ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
275
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
276 retval = bitopx (fname, x, y);
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
277 }
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
278 else
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14725
diff changeset
279 error ("%s: invalid operand type", fname.c_str ());
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
280 }
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
281 }
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
282 else if (args(0).class_name () == args(1).class_name ())
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
283 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
284 if (args(0).type_id () == octave_uint64_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
285 || args(0).type_id () == octave_uint64_scalar::static_type_id ())
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
286 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
287 uint64NDArray x = args(0).uint64_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
288 uint64NDArray y = args(1).uint64_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
289
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
290 retval = bitopx (fname, x, y);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
291 }
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
292 else if (args(0).type_id () == octave_uint32_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
293 || args(0).type_id () == octave_uint32_scalar::static_type_id ())
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
294 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
295 uint32NDArray x = args(0).uint32_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
296 uint32NDArray y = args(1).uint32_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
297
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
298 retval = bitopx (fname, x, y);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
299 }
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
300 else if (args(0).type_id () == octave_uint16_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
301 || args(0).type_id () == octave_uint16_scalar::static_type_id ())
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
302 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
303 uint16NDArray x = args(0).uint16_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
304 uint16NDArray y = args(1).uint16_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
305
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
306 retval = bitopx (fname, x, y);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
307 }
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
308 else if (args(0).type_id () == octave_uint8_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
309 || args(0).type_id () == octave_uint8_scalar::static_type_id ())
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
310 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
311 uint8NDArray x = args(0).uint8_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
312 uint8NDArray y = args(1).uint8_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
313
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
314 retval = bitopx (fname, x, y);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
315 }
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
316 else if (args(0).type_id () == octave_int64_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
317 || args(0).type_id () == octave_int64_scalar::static_type_id ())
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
318 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
319 int64NDArray x = args(0).int64_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
320 int64NDArray y = args(1).int64_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
321
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
322 retval = bitopx (fname, x, y);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
323 }
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
324 else if (args(0).type_id () == octave_int32_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
325 || args(0).type_id () == octave_int32_scalar::static_type_id ())
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
326 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
327 int32NDArray x = args(0).int32_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
328 int32NDArray y = args(1).int32_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
329
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
330 retval = bitopx (fname, x, y);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
331 }
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
332 else if (args(0).type_id () == octave_int16_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
333 || args(0).type_id () == octave_int16_scalar::static_type_id ())
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
334 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
335 int16NDArray x = args(0).int16_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
336 int16NDArray y = args(1).int16_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
337
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
338 retval = bitopx (fname, x, y);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
339 }
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
340 else if (args(0).type_id () == octave_int8_matrix::static_type_id ()
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
341 || args(0).type_id () == octave_int8_scalar::static_type_id ())
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
342 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
343 int8NDArray x = args(0).int8_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
344 int8NDArray y = args(1).int8_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
345
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
346 retval = bitopx (fname, x, y);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
347 }
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
348 else
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
349 error ("%s: invalid operand type", fname.c_str ());
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
350 }
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
351 else
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
352 error ("%s: must have matching operand types", fname.c_str ());
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
353
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
354 return retval;
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
355 }
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
356
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
357 DEFUN (bitand, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
358 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20804
diff changeset
359 @deftypefn {} {} 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
360 Return the bitwise AND of non-negative integers.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
361 \n\
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
362 @var{x}, @var{y} must be in the range [0,intmax]\n\
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
363 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, intmax, flintmax}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
364 @end deftypefn")
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
365 {
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
366 return bitop ("bitand", args);
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
367 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
368
20870
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
369 /*
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
370 %!# Function bitand is tested as part of bitxor BIST tests
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
371 */
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
372
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
373 DEFUN (bitor, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
374 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20804
diff changeset
375 @deftypefn {} {} bitor (@var{x}, @var{y})\n\
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
376 Return the bitwise OR of non-negative integers @var{x} and @var{y}.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
377 \n\
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
378 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, intmax, flintmax}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
379 @end deftypefn")
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
380 {
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
381 return bitop ("bitor", args);
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
382 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
383
20870
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
384 /*
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
385 %!# Function bitor is tested as part of bitxor BIST tests
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
386 */
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
387
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
388 DEFUN (bitxor, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
389 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20804
diff changeset
390 @deftypefn {} {} bitxor (@var{x}, @var{y})\n\
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
391 Return the bitwise XOR of non-negative integers @var{x} and @var{y}.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
392 \n\
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
393 @seealso{bitand, bitor, bitset, bitget, bitcmp, bitshift, intmax, flintmax}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
394 @end deftypefn")
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
395 {
14631
57e4ff70b7c1 Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14138
diff changeset
396 return bitop ("bitxor", args);
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
397 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
398
19146
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
399 /*
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
400 %!assert (bitand (true, false), false)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
401 %!assert (bitor (true, false), true)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
402 %!assert (bitxor (true, false), true)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
403
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
404 %!assert (bitand (true, true), true)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
405 %!assert (bitor (true, true), true)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
406 %!assert (bitxor (true, true), false)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
407
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
408 %!assert (bitand (true, 5), 1)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
409
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
410 %!assert (bitand (true, false), false)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
411 %!assert (bitand (true, true), true)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
412 %!assert (bitand (true, false), false)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
413 %!assert (bitand (true, false), false)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
414
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
415 ## Test idx_arg.length () == 0
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
416 %!error <size of X and Y must match> bitand ([0 0 0], [1 0])
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
417 %!error <size of X and Y must match> bitand ([0; 0; 0], [0 0 0])
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
418 */
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
419
17389
dbdff94bf977 Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents: 17281
diff changeset
420 template <typename T>
dbdff94bf977 Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents: 17281
diff changeset
421 static int64_t
dbdff94bf977 Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents: 17281
diff changeset
422 max_mantissa_value ()
dbdff94bf977 Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents: 17281
diff changeset
423 {
dbdff94bf977 Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents: 17281
diff changeset
424 return (static_cast<int64_t> (1) << std::numeric_limits<T>::digits) - 1;
dbdff94bf977 Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents: 17281
diff changeset
425 }
dbdff94bf977 Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents: 17281
diff changeset
426
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
427 static int64_t
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
428 bitshift (double a, int n, int64_t mask)
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
429 {
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
430 // In the name of bug-for-bug compatibility.
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
431 if (a < 0)
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
432 return -bitshift (-a, n, mask);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5828
diff changeset
433
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
434 if (n > 0)
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
435 return (static_cast<int64_t> (a) << n) & mask;
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
436 else if (n < 0)
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
437 return (static_cast<int64_t> (a) >> -n) & mask;
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
438 else
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
439 return static_cast<int64_t> (a) & mask;
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
440 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
441
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
442 static int64_t
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
443 bitshift (float a, int n, int64_t mask)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
444 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
445 // In the name of bug-for-bug compatibility.
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
446 if (a < 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
447 return -bitshift (-a, n, mask);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
448
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
449 if (n > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
450 return (static_cast<int64_t> (a) << n) & mask;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
451 else if (n < 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
452 return (static_cast<int64_t> (a) >> -n) & mask;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
453 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
454 return static_cast<int64_t> (a) & mask;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
455 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7763
diff changeset
456
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
457 // 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
458 // 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
459 // shift.
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
460
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
461 #define DO_BITSHIFT(T) \
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
462 double d1, d2; \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
463 \
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
464 if (! n.all_integers (d1, d2)) \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
465 error ("bitshift: K must be a scalar or array of integers"); \
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20486
diff changeset
466 \
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
467 int m_nel = m.numel (); \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
468 int n_nel = n.numel (); \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
469 \
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
470 bool is_scalar_op = (m_nel == 1 || n_nel == 1); \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
471 \
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
472 dim_vector m_dv = m.dims (); \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
473 dim_vector n_dv = n.dims (); \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
474 \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
475 bool is_array_op = (m_dv == n_dv); \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
476 \
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
477 if (! is_array_op && ! is_scalar_op) \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
478 error ("bitshift: size of A and N must match, or one operand must be a scalar"); \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
479 \
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
480 T ## NDArray result; \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
481 \
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
482 if (m_nel != 1) \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
483 result.resize (m_dv); \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
484 else \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
485 result.resize (n_dv); \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
486 \
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
487 for (int i = 0; i < m_nel; i++) \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
488 if (is_scalar_op) \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
489 for (int k = 0; k < n_nel; k++) \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
490 if (static_cast<int> (n(k)) >= bits_in_type) \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
491 result(i+k) = 0; \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
492 else \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
493 result(i+k) = bitshift (m(i), static_cast<int> (n(k)), mask); \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
494 else \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
495 if (static_cast<int> (n(i)) >= bits_in_type) \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
496 result(i) = 0; \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
497 else \
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
498 result(i) = bitshift (m(i), static_cast<int> (n(i)), mask); \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
499 \
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
500 retval = result;
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
501
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
502 #define DO_UBITSHIFT(T, N) \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
503 do \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
504 { \
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
505 int bits_in_type = octave_ ## T :: nbits (); \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
506 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
507 octave_ ## T mask = octave_ ## T::max (); \
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
508 if ((N) < bits_in_type) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
509 mask = bitshift (mask, (N) - bits_in_type); \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
510 else if ((N) < 1) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
511 mask = 0; \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
512 DO_BITSHIFT (T); \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
513 } \
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
514 while (0)
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
515
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
516 #define DO_SBITSHIFT(T, N) \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
517 do \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
518 { \
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
519 int bits_in_type = octave_ ## T :: nbits (); \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
520 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
521 octave_ ## T mask = octave_ ## T::max (); \
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
522 if ((N) < bits_in_type) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
523 mask = bitshift (mask, (N) - bits_in_type); \
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
524 else if ((N) < 1) \
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
525 mask = 0; \
9440
357cff83985d fix signed integer shift
Jaroslav Hajek <highegg@gmail.com>
parents: 9209
diff changeset
526 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
527 DO_BITSHIFT (T); \
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
528 } \
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
529 while (0)
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
530
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
531 DEFUN (bitshift, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
532 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20804
diff changeset
533 @deftypefn {} {} bitshift (@var{a}, @var{k})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20804
diff changeset
534 @deftypefnx {} {} bitshift (@var{a}, @var{k}, @var{n})\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
535 Return a @var{k} bit shift of @var{n}-digit unsigned integers in @var{a}.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
536 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
537 A positive @var{k} leads to a left shift; A negative value to a right shift.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
538 \n\
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
539 If @var{n} is omitted it defaults to 64.\n\
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
540 @var{n} must be in the range [1,64].\n\
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
541 \n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
542 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
543 @group\n\
7097
e8c94e473c68 [project @ 2007-11-02 17:24:23 by jwe]
jwe
parents: 7017
diff changeset
544 bitshift (eye (3), 1)\n\
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
545 @result{}\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
546 @group\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
547 2 0 0\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
548 0 2 0\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
549 0 0 2\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
550 @end group\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
551 \n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
552 bitshift (10, [-2, -1, 0, 1, 2])\n\
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
553 @result{} 2 5 10 20 40\n\
17861
870f3e12e163 maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents: 17787
diff changeset
554 @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
555 @c\n\
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
556 @c\n\
6439
a37c427ae9d1 [project @ 2007-03-23 15:04:01 by jwe]
jwe
parents: 6108
diff changeset
557 @c bitshift ([1, 10], 2, [3,4])\n\
a37c427ae9d1 [project @ 2007-03-23 15:04:01 by jwe]
jwe
parents: 6108
diff changeset
558 @c @result{} 4 8\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
559 @end group\n\
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
560 @end example\n\
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
561 @seealso{bitand, bitor, bitxor, bitset, bitget, bitcmp, intmax, flintmax}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
562 @end deftypefn")
4908
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 int nargin = args.length ();
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
565
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
566 if (nargin < 2 || nargin > 3)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
567 print_usage ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
568
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
569 NDArray n = args(1).xarray_value ("bitshift: K must be a scalar or array of integers");
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
570
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
571 int nbits = 64;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
572
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
573 if (nargin == 3)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
574 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
575 // FIXME: for compatibility, we should accept an array or a scalar
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
576 // as the third argument.
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
577 if (args(2).numel () > 1)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
578 error ("bitshift: N must be a scalar integer");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
579
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
580 nbits = args(2).xint_value ("bitshift: N must be an integer");
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
581
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
582 if (nbits < 0)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
583 error ("bitshift: N must be positive");
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
584 }
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
585
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
586 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
587
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
588 octave_value m_arg = args(0);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
589 std::string cname = m_arg.class_name ();
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
590
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
591 if (cname == "double")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
592 {
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
593 static const int bits_in_mantissa
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
594 = std::numeric_limits<double>::digits;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
595
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
596 nbits = (nbits < bits_in_mantissa ? nbits : bits_in_mantissa);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
597 int64_t mask = max_mantissa_value<double> ();
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
598 if (nbits < bits_in_mantissa)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
599 mask = mask >> (bits_in_mantissa - nbits);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
600 else if (nbits < 1)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
601 mask = 0;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
602 int bits_in_type = sizeof (double)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
603 * std::numeric_limits<unsigned char>::digits;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
604 NDArray m = m_arg.array_value ();
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
605 DO_BITSHIFT ();
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
606 }
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
607 else if (cname == "uint8")
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
608 DO_UBITSHIFT (uint8, nbits < 8 ? nbits : 8);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
609 else if (cname == "uint16")
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
610 DO_UBITSHIFT (uint16, nbits < 16 ? nbits : 16);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
611 else if (cname == "uint32")
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
612 DO_UBITSHIFT (uint32, nbits < 32 ? nbits : 32);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
613 else if (cname == "uint64")
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
614 DO_UBITSHIFT (uint64, nbits < 64 ? nbits : 64);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
615 else if (cname == "int8")
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
616 DO_SBITSHIFT (int8, nbits < 8 ? nbits : 8);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
617 else if (cname == "int16")
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
618 DO_SBITSHIFT (int16, nbits < 16 ? nbits : 16);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
619 else if (cname == "int32")
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
620 DO_SBITSHIFT (int32, nbits < 32 ? nbits : 32);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
621 else if (cname == "int64")
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
622 DO_SBITSHIFT (int64, nbits < 64 ? nbits : 64);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
623 else if (cname == "single")
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
624 {
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
625 static const int bits_in_mantissa
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
626 = std::numeric_limits<float>::digits;
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
627 nbits = (nbits < bits_in_mantissa ? nbits : bits_in_mantissa);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
628 int64_t mask = max_mantissa_value<float> ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
629 if (nbits < bits_in_mantissa)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
630 mask = mask >> (bits_in_mantissa - nbits);
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
631 else if (nbits < 1)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
632 mask = 0;
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
633 int bits_in_type = sizeof (float)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
634 * std::numeric_limits<unsigned char>::digits;
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
635 FloatNDArray m = m_arg.float_array_value ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
636 DO_BITSHIFT (Float);
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
637 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
638 else
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
639 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
640
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
641 return retval;
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
642 }
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
643
19146
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
644 /*
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
645 %!assert (bitshift (uint8 (16), 1), uint8 ( 32))
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
646 %!assert (bitshift (uint16 (16), 2), uint16 ( 64))
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
647 %!assert (bitshift (uint32 (16), 3), uint32 (128))
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
648 %!assert (bitshift (uint64 (16), 4), uint64 (256))
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
649 %!assert (bitshift (uint8 (255), 1), uint8 (254))
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
650
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20704
diff changeset
651 %!error <K must be a scalar or array of integers> bitshift (16, 1.5)
19146
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
652 %!error bitshift (16, {1})
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
653 %!error <N must be a scalar integer> bitshift (10, [-2 -1 0 1 2], [1 1 1 1 1])
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
654 %!error <N must be positive> bitshift (10, [-2 -1 0 1 2], -1)
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
655 */
a84f0182f912 bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents: 18678
diff changeset
656
17390
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
657 DEFUN (flintmax, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
658 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20804
diff changeset
659 @deftypefn {} {} flintmax ()\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20804
diff changeset
660 @deftypefnx {} {} flintmax (\"double\")\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20804
diff changeset
661 @deftypefnx {} {} flintmax (\"single\")\n\
17390
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
662 Return the largest integer that can be represented consecutively in a\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
663 floating point value.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
664 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
665 The default class is @qcode{\"double\"}, but @qcode{\"single\"} is a valid\n\
21547
ad0599a0acc6 doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 21301
diff changeset
666 option. On IEEE 754 compatible systems, @code{flintmax} is\n\
ad0599a0acc6 doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 21301
diff changeset
667 @w{@math{2^{53}}} for @qcode{\"double\"} and @w{@math{2^{24}}} for\n\
ad0599a0acc6 doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 21301
diff changeset
668 @qcode{\"single\"}.\n\
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
669 @seealso{intmax, realmax, realmin}\n\
17390
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
670 @end deftypefn")
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
671 {
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
672 int nargin = args.length ();
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
673
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
674 if (nargin > 1)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
675 print_usage ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
676
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
677 std::string cname = "double";
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
678 if (nargin == 1)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
679 cname = args(0).xstring_value ("flintmax: argument must be a string");
17390
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
680
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
681 if (cname == "double")
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
682 return ovl (static_cast<double> (max_mantissa_value<double> () + 1));
17390
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
683 else if (cname == "single")
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
684 return ovl (static_cast<float> (max_mantissa_value<float> () + 1));
17390
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
685 else
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
686 error ("flintmax: not defined for class '%s'", cname.c_str ());
4bcd301754ce Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents: 17389
diff changeset
687 }
16939
06897f865f0b Add flintmax() as an alias for function bitmax().
Rik <rik@octave.org>
parents: 15195
diff changeset
688
20870
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
689 /*
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
690 %!assert (flintmax (), 2^53)
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
691 %!assert (flintmax ("double"), 2^53)
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
692 %!assert (flintmax ("single"), single (2^24))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
693
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
694 %!error flintmax (0)
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
695 %!error flintmax ("double", 0)
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
696 %!error flintmax ("int32")
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
697 %!error flintmax ("char")
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
698 */
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
699
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
700 DEFUN (intmax, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
701 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20804
diff changeset
702 @deftypefn {} {} intmax (@var{type})\n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
703 Return the largest integer that can be represented in an integer type.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
704 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
705 The variable @var{type} can be\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
706 \n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
707 @table @code\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
708 @item int8\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
709 signed 8-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
710 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
711 @item int16\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
712 signed 16-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
713 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
714 @item int32\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
715 signed 32-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
716 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
717 @item int64\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
718 signed 64-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
719 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
720 @item uint8\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
721 unsigned 8-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
722 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
723 @item uint16\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
724 unsigned 16-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
725 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
726 @item uint32\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
727 unsigned 32-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
728 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
729 @item uint64\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
730 unsigned 64-bit integer.\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
731 @end table\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
732 \n\
18155
20f2b3c48c4c intmax, intmin: Fix default integer type in docstrings
Mike Miller <mtmiller@ieee.org>
parents: 17861
diff changeset
733 The default for @var{type} is @code{int32}.\n\
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
734 @seealso{intmin, flintmax}\n\
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
735 @end deftypefn")
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
736 {
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
737 int nargin = args.length ();
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
738
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
739 if (nargin > 1)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
740 print_usage ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
741
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
742 std::string cname = "int32";
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
743 if (nargin == 1)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
744 cname = args(0).xstring_value ("intmax: argument must be a string");
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
745
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
746 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
747
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
748 if (cname == "uint8")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
749 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
750 else if (cname == "uint16")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
751 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
752 else if (cname == "uint32")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
753 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
754 else if (cname == "uint64")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
755 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
756 else if (cname == "int8")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
757 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
758 else if (cname == "int16")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
759 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
760 else if (cname == "int32")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
761 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
762 else if (cname == "int64")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
763 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
764 else
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
765 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
766
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
767 return retval;
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
768 }
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
769
20870
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
770 /*
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
771 %!assert (intmax (), int32 (2^31 - 1))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
772 %!assert (intmax ("int8"), int8 (2^7 - 1))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
773 %!assert (intmax ("uint8"), uint8 (2^8 - 1))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
774 %!assert (intmax ("int16"), int16 (2^15 - 1))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
775 %!assert (intmax ("uint16"), uint16 (2^16 - 1))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
776 %!assert (intmax ("int32"), int32 (2^31 - 1))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
777 %!assert (intmax ("uint32"), uint32 (2^32 - 1))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
778 %!assert (intmax ("int64"), int64 (2^63 - 1))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
779 %!assert (intmax ("uint64"), uint64 (2^64 - 1))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
780
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
781 %!error intmax (0)
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
782 %!error intmax ("int32", 0)
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
783 %!error intmax ("double")
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
784 %!error intmax ("char")
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
785 */
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
786
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
787 DEFUN (intmin, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
788 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20804
diff changeset
789 @deftypefn {} {} intmin (@var{type})\n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
790 Return the smallest integer that can be represented in an integer type.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
791 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
792 The variable @var{type} can be\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
793 \n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
794 @table @code\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
795 @item int8\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
796 signed 8-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
797 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
798 @item int16\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
799 signed 16-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
800 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
801 @item int32\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
802 signed 32-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
803 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
804 @item int64\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
805 signed 64-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
806 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
807 @item uint8\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
808 unsigned 8-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
809 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
810 @item uint16\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
811 unsigned 16-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
812 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
813 @item uint32\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
814 unsigned 32-bit integer.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10830
diff changeset
815 \n\
5040
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
816 @item uint64\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
817 unsigned 64-bit integer.\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
818 @end table\n\
b6ff3a0d3d17 [project @ 2004-09-27 13:50:01 by jwe]
jwe
parents: 4952
diff changeset
819 \n\
18155
20f2b3c48c4c intmax, intmin: Fix default integer type in docstrings
Mike Miller <mtmiller@ieee.org>
parents: 17861
diff changeset
820 The default for @var{type} is @code{int32}.\n\
20486
4bb41929286b Deprecate bitmax.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20425
diff changeset
821 @seealso{intmax, flintmax}\n\
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
822 @end deftypefn")
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
823 {
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
824 int nargin = args.length ();
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
825
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
826 if (nargin > 1)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
827 print_usage ();
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
828
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
829 std::string cname = "int32";
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
830 if (nargin == 1)
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
831 cname = args(0).xstring_value ("intmin: argument must be a string");
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
832
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
833 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20870
diff changeset
834
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
835 if (cname == "uint8")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
836 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
837 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
838 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
839 else if (cname == "uint32")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
840 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
841 else if (cname == "uint64")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
842 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
843 else if (cname == "int8")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
844 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
845 else if (cname == "int16")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
846 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
847 else if (cname == "int32")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
848 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
849 else if (cname == "int64")
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
850 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
851 else
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4908
diff changeset
852 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
853
4908
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
854 return retval;
66af4b9f451e [project @ 2004-06-29 19:20:00 by jwe]
jwe
parents:
diff changeset
855 }
10811
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
856
20870
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
857 /*
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
858 %!assert (intmin (), int32 (-2^31))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
859 %!assert (intmin ("int8"), int8 (-2^7))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
860 %!assert (intmin ("uint8"), uint8 (-2^8))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
861 %!assert (intmin ("int16"), int16 (-2^15))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
862 %!assert (intmin ("uint16"), uint16 (-2^16))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
863 %!assert (intmin ("int32"), int32 (-2^31))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
864 %!assert (intmin ("uint32"), uint32 (-2^32))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
865 %!assert (intmin ("int64"), int64 (-2^63))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
866 %!assert (intmin ("uint64"), uint64 (-2^64))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
867
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
868 %!error intmin (0)
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
869 %!error intmin ("int32", 0)
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
870 %!error intmin ("double")
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
871 %!error intmin ("char")
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
872 */
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
873
10811
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
874 DEFUN (sizemax, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
875 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20804
diff changeset
876 @deftypefn {} {} sizemax ()\n\
10895
4176c5c62138 Imrove documentation string for sizemax
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
877 Return the largest value allowed for the size of an array.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19864
diff changeset
878 \n\
10811
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
879 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
880 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
881 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
882 by @code{intmax}.\n\
10811
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
883 @seealso{intmax}\n\
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
884 @end deftypefn")
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
885 {
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
886 if (args.length () != 0)
10811
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
887 print_usage ();
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
888
20804
a6eaedd8bd75 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
889 return octave_value (octave_int<octave_idx_type> (dim_vector::dim_max ()));
10811
e38c071bbc41 allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
890 }
20870
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
891
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
892 /*
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
893 %!assert (sizemax () >= (intmax ("int32") - 1))
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
894
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
895 %!error sizemax (0)
020b71557b12 2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents: 20853
diff changeset
896 */