Mercurial > octave
annotate libinterp/corefcn/bitfcns.cc @ 31605:e88a07dec498 stable
maint: Use macros to begin/end C++ namespaces.
* oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE,
OCTAVE_END_NAMESPACE) that can be used to start/end a namespace.
* mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc,
__dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc,
__ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc,
__magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc,
auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h,
besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h,
call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc,
colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc,
defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc,
display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc,
ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h,
event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc,
fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc,
ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc,
getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc,
gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc,
graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc,
help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h,
interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h,
inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc,
ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h,
mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc,
oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h,
oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h,
oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h,
oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy,
ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc,
pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc,
qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h,
sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc,
sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h,
stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc,
symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h,
symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h,
text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc,
toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc,
url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc,
variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h,
__delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc,
audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh,
mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc,
ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc,
ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h,
ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc,
ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h,
ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, 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-cell.cc,
op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.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-dm.cc, op-dm-scm.cc, op-dm-sm.cc,
op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc,
op-fcm-fcs.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-fdm.cc, op-fm-fcm.cc,
op-fm-fcs.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-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc,
op-m-scm.cc, op-m-sm.cc, op-mi.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, ops.h,
anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h,
comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc,
oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h,
pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h,
pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h,
pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h,
pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h,
pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc,
pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc,
pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc,
pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc,
pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc,
pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc,
pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h,
pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h,
range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc,
chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h,
lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h,
oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc,
qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc,
randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc,
sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc,
child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc,
file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h,
mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h,
oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc,
oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h,
base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h,
file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc,
lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h,
oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h,
oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h,
oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h,
pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h,
url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 01 Dec 2022 14:23:45 -0800 |
parents | 32d2b6604a9f |
children | aac27ad79be6 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30390
diff
changeset
|
3 // Copyright (C) 2004-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
4908 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
4908 | 28 #endif |
29 | |
17396 | 30 #include <limits> |
31 | |
4908 | 32 #include "str-vec.h" |
33 #include "quit.h" | |
34 | |
35 #include "defun.h" | |
36 #include "error.h" | |
37 #include "ov.h" | |
38 #include "ov-uint64.h" | |
4915 | 39 #include "ov-uint32.h" |
40 #include "ov-uint16.h" | |
41 #include "ov-uint8.h" | |
42 #include "ov-int64.h" | |
43 #include "ov-int32.h" | |
44 #include "ov-int16.h" | |
45 #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
|
46 #include "ov-float.h" |
4915 | 47 #include "ov-scalar.h" |
48 #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
|
49 #include "ov-bool.h" |
4908 | 50 |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
51 #include <functional> |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
52 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
53 #if ! defined (HAVE_CXX_BITWISE_OP_TEMPLATES) |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
54 OCTAVE_BEGIN_NAMESPACE(std) |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
55 |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
56 template <typename T> |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
57 struct bit_and |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
58 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
59 public: |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29958
diff
changeset
|
60 T operator() (const T& op1, const T& op2) const { return (op1 & op2); } |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
61 }; |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
62 |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
63 template <typename T> |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 struct bit_or |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
65 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
66 public: |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29958
diff
changeset
|
67 T operator() (const T& op1, const T& op2) const { return (op1 | op2); } |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
68 }; |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
69 |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
70 template <typename T> |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 struct bit_xor |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
72 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
73 public: |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29958
diff
changeset
|
74 T operator() (const T& op1, const T& op2) const { return (op1 ^ op2); } |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
75 }; |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
76 |
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
77 OCTAVE_END_NAMESPACE(std) |
14725
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
78 #endif |
fa48fd0f160f
Add configure check for templated bitwise operators.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
14631
diff
changeset
|
79 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
80 OCTAVE_BEGIN_NAMESPACE(octave) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
81 |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
82 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
|
83 octave_value |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
84 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
|
85 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
|
86 { |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
87 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
|
88 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
|
89 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
90 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
|
91 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
92 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
|
93 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
|
94 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
95 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
|
96 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
101 Array<T> result; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
102 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
103 if (nelx != 1) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
104 result.resize (dvx); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
105 else |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
106 result.resize (dvy); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
107 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
108 for (int i = 0; i < nelx; i++) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
109 if (is_scalar_op) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
110 for (int k = 0; k < nely; k++) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
111 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
|
112 else |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
113 result(i) = op (x(i), y(i)); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
114 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
115 return result; |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
116 } |
4908 | 117 |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
118 // Trampoline function, instantiates the proper template above, with |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
119 // reflective information hardwired. We can't hardwire this information |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
120 // 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
|
121 // 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
|
122 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
|
123 octave_value |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
124 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
|
125 { |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
126 if (fname == "bitand") |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
127 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
|
128 if (fname == "bitor") |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
129 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
|
130 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
131 //else (fname == "bitxor") |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
132 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
|
133 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
134 |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
135 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
|
136 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
|
137 { |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
138 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
|
139 && 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
|
140 && 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_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
|
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_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
|
147 } |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
148 |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
149 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
|
150 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
|
151 { |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
152 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
|
153 } |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
154 |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
155 octave_value |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
156 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
|
157 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
158 if (args.length () != 2) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
159 print_usage (); |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
160 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
161 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
162 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
163 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
|
164 || 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
|
165 || 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
|
166 || 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
|
167 || 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
|
168 || 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
|
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_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
|
171 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
|
172 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
173 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
|
174 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
|
175 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
176 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
|
177 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
|
178 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
179 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
|
180 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
181 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
|
182 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
183 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
|
184 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
|
185 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
186 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
|
187 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
188 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
|
189 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
190 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
|
191 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
|
192 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
193 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
|
194 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
195 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
|
196 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
197 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
|
198 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
|
199 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
200 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
|
201 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
202 else |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
203 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
204 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
|
205 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
|
206 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
207 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
|
208 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
|
209 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
210 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
|
211 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
212 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
213 else |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
214 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
215 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
|
216 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
|
217 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
218 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
|
219 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
220 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
|
221 || 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
|
222 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
223 uint64NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
224 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
|
225 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
226 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
227 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
228 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
|
229 || 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
|
230 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
231 uint32NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
232 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
|
233 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
234 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
|
235 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
236 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
|
237 || 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
|
238 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
239 uint16NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
240 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
|
241 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
242 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
|
243 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
244 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
|
245 || 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
|
246 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
247 uint8NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
248 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
|
249 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
250 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
|
251 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
252 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
|
253 || 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
|
254 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
255 int64NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
256 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
|
257 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
258 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
|
259 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
260 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
|
261 || 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
|
262 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
263 int32NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
264 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
|
265 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
266 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
|
267 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
268 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
|
269 || 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
|
270 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
271 int16NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
272 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
|
273 |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
274 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
|
275 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
276 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
|
277 || 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
|
278 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
279 int8NDArray x (dx); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
280 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
|
281 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20486
diff
changeset
|
282 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
|
283 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
284 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
|
285 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
|
286 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
287 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
288 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
|
289 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
290 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
|
291 || 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
|
292 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
293 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
|
294 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
|
295 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
296 retval = bitopx (fname, x, y); |
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 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
|
299 || 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
|
300 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
301 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
|
302 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
|
303 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
304 retval = bitopx (fname, x, y); |
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 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
|
307 || 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
|
308 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
309 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
|
310 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
|
311 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
312 retval = bitopx (fname, x, y); |
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 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
|
315 || 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
|
316 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
317 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
|
318 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
|
319 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
320 retval = bitopx (fname, x, y); |
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 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
|
323 || 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
|
324 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
325 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
|
326 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
|
327 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
328 retval = bitopx (fname, x, y); |
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 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
|
331 || 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
|
332 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
333 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
|
334 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
|
335 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
336 retval = bitopx (fname, x, y); |
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 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
|
339 || 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
|
340 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
341 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
|
342 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
|
343 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
344 retval = bitopx (fname, x, y); |
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 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
|
347 || 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
|
348 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
349 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
|
350 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
|
351 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
352 retval = bitopx (fname, x, y); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
353 } |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
354 else |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
355 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
|
356 } |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
357 else |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
358 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
|
359 |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
360 return retval; |
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
361 } |
4908 | 362 |
363 DEFUN (bitand, args, , | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
364 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
365 @deftypefn {} {@var{z} =} bitand (@var{x}, @var{y}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
366 Return the bitwise AND of non-negative integers. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
367 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
368 @var{x}, @var{y} must be in the range [0,intmax] |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
369 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, intmax, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
370 @end deftypefn */) |
4908 | 371 { |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
372 return bitop ("bitand", args); |
4908 | 373 } |
374 | |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
375 /* |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
376 %!# 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
|
377 */ |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
378 |
4908 | 379 DEFUN (bitor, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
380 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
381 @deftypefn {} {@var{z} =} bitor (@var{x}, @var{y}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
382 Return the bitwise OR of non-negative integers @var{x} and @var{y}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
383 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
384 @seealso{bitor, bitxor, bitset, bitget, bitcmp, bitshift, intmax, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
385 @end deftypefn */) |
4908 | 386 { |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
387 return bitop ("bitor", args); |
4908 | 388 } |
389 | |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
390 /* |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
391 %!# 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
|
392 */ |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
393 |
4908 | 394 DEFUN (bitxor, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
395 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
396 @deftypefn {} {@var{z} =} bitxor (@var{x}, @var{y}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
397 Return the bitwise XOR of non-negative integers @var{x} and @var{y}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
398 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
399 @seealso{bitand, bitor, bitset, bitget, bitcmp, bitshift, intmax, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
400 @end deftypefn */) |
4908 | 401 { |
14631
57e4ff70b7c1
Use more templates in bitwise operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
402 return bitop ("bitxor", args); |
4908 | 403 } |
404 | |
19146
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
405 /* |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
406 %!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
|
407 %!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
|
408 %!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
|
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, true), true) |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
411 %!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
|
412 %!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
|
413 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
414 %!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
|
415 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
416 %!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
|
417 %!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
|
418 %!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
|
419 %!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
|
420 |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
421 ## 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
|
422 %!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
|
423 %!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
|
424 */ |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
425 |
17389
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
426 template <typename T> |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
427 static int64_t |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
428 max_mantissa_value () |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
429 { |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
430 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
|
431 } |
dbdff94bf977
Use std::numeric_limits for floating point bit widths
Mike Miller <mtmiller@ieee.org>
parents:
17281
diff
changeset
|
432 |
5828 | 433 static int64_t |
434 bitshift (double a, int n, int64_t mask) | |
4908 | 435 { |
6108 | 436 // In the name of bug-for-bug compatibility. |
437 if (a < 0) | |
438 return -bitshift (-a, n, mask); | |
439 | |
4915 | 440 if (n > 0) |
5828 | 441 return (static_cast<int64_t> (a) << n) & mask; |
4915 | 442 else if (n < 0) |
5828 | 443 return (static_cast<int64_t> (a) >> -n) & mask; |
4915 | 444 else |
5828 | 445 return static_cast<int64_t> (a) & mask; |
4908 | 446 } |
447 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
448 static int64_t |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
449 bitshift (float a, int n, int64_t mask) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
450 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
451 // In the name of bug-for-bug compatibility. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
452 if (a < 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
453 return -bitshift (-a, n, mask); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
454 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
455 if (n > 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
456 return (static_cast<int64_t> (a) << n) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
457 else if (n < 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
458 return (static_cast<int64_t> (a) >> -n) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
459 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
460 return static_cast<int64_t> (a) & mask; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
461 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7763
diff
changeset
|
462 |
4919 | 463 // Note that the bitshift operators are undefined if shifted by more |
464 // bits than in the type, so we need to test for the size of the | |
465 // shift. | |
466 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
467 #define DO_BITSHIFT(T) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
468 double d1, d2; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
469 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
470 if (! n.all_integers (d1, d2)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
471 error ("bitshift: K must be a scalar or array of integers"); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
472 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
473 int m_nel = m.numel (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
474 int n_nel = n.numel (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
475 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
476 bool is_scalar_op = (m_nel == 1 || n_nel == 1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
477 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
478 dim_vector m_dv = m.dims (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
479 dim_vector n_dv = n.dims (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
480 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
481 bool is_array_op = (m_dv == n_dv); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
482 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
483 if (! is_array_op && ! is_scalar_op) \ |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
484 error ("bitshift: size of A and N must match, or one operand must be a scalar"); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
485 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
486 T ## NDArray result; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
487 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
488 if (m_nel != 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
489 result.resize (m_dv); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
490 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
491 result.resize (n_dv); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
492 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
493 for (int i = 0; i < m_nel; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
494 if (is_scalar_op) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
495 for (int k = 0; k < n_nel; k++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
496 if (static_cast<int> (n(k)) >= bits_in_type) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
497 result(i+k) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
498 else \ |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
499 result(i+k) = bitshift (m(i), static_cast<int> (n(k)), mask); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
500 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
501 if (static_cast<int> (n(i)) >= bits_in_type) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
502 result(i) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
503 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
504 result(i) = bitshift (m(i), static_cast<int> (n(i)), mask); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
505 \ |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
506 retval = result; |
4915 | 507 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
508 #define DO_UBITSHIFT(T, N) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
509 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
510 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
511 int bits_in_type = octave_ ## T :: nbits (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
512 T ## NDArray m = m_arg.T ## _array_value (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
513 octave_ ## T mask = octave_ ## T::max (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
514 if ((N) < bits_in_type) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
515 mask = bitshift (mask, (N) - bits_in_type); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
516 else if ((N) < 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
517 mask = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
518 DO_BITSHIFT (T); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
519 } \ |
4915 | 520 while (0) |
521 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
522 #define DO_SBITSHIFT(T, N) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
523 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
524 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
525 int bits_in_type = octave_ ## T :: nbits (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
526 T ## NDArray m = m_arg.T ## _array_value (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
527 octave_ ## T mask = octave_ ## T::max (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
528 if ((N) < bits_in_type) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
529 mask = bitshift (mask, (N) - bits_in_type); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
530 else if ((N) < 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
531 mask = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
532 /* FIXME: 2's complement only? */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
533 mask = mask | octave_ ## T :: min (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
534 DO_BITSHIFT (T); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
535 } \ |
4908 | 536 while (0) |
537 | |
538 DEFUN (bitshift, args, , | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
539 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
540 @deftypefn {} {@var{B} =} bitshift (@var{A}, @var{k}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
541 @deftypefnx {} {@var{B} =} bitshift (@var{A}, @var{k}, @var{n}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
542 Return a @var{k} bit shift of @var{n}-digit unsigned integers in @var{A}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
543 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
544 A positive @var{k} leads to a left shift; A negative value to a right shift. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
545 |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
546 If @var{n} is omitted it defaults to 64. @var{n} must be in the range [1,64]. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
547 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
548 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
549 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
550 bitshift (eye (3), 1) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
551 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
552 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
553 2 0 0 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
554 0 2 0 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
555 0 0 2 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
556 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
557 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
558 bitshift (10, [-2, -1, 0, 1, 2]) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
559 @result{} 2 5 10 20 40 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
560 @c FIXME: restore this example when third arg is allowed to be an array. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
561 @c |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
562 @c |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
563 @c bitshift ([1, 10], 2, [3,4]) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
564 @c @result{} 4 8 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
565 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
566 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
567 @seealso{bitand, bitor, bitxor, bitset, bitget, bitcmp, intmax, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
568 @end deftypefn */) |
4908 | 569 { |
570 int nargin = args.length (); | |
571 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
572 if (nargin < 2 || nargin > 3) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
573 print_usage (); |
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 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
|
576 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
577 int nbits = 64; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
578 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
579 if (nargin == 3) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
580 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
581 // 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
|
582 // as the third argument. |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
583 if (args(2).numel () > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
584 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
|
585 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
586 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
|
587 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
588 if (nbits < 0) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
589 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
|
590 } |
4915 | 591 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
592 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
593 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
594 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
|
595 std::string cname = m_arg.class_name (); |
4908 | 596 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
597 if (cname == "double") |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
598 { |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
599 static const int bits_in_mantissa |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
600 = std::numeric_limits<double>::digits; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
601 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
602 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
|
603 int64_t mask = max_mantissa_value<double> (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
604 if (nbits < bits_in_mantissa) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
605 mask = mask >> (bits_in_mantissa - nbits); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
606 int bits_in_type = sizeof (double) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
607 * std::numeric_limits<unsigned char>::digits; |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
608 NDArray m = m_arg.array_value (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
609 DO_BITSHIFT (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
610 } |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
611 else if (cname == "uint8") |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
612 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
|
613 else if (cname == "uint16") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
614 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
|
615 else if (cname == "uint32") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
616 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
|
617 else if (cname == "uint64") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
618 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
|
619 else if (cname == "int8") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
620 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
|
621 else if (cname == "int16") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
622 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
|
623 else if (cname == "int32") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
624 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
|
625 else if (cname == "int64") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
626 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
|
627 else if (cname == "single") |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
628 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
629 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
|
630 = std::numeric_limits<float>::digits; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
631 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
|
632 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
|
633 if (nbits < bits_in_mantissa) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
634 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
|
635 int bits_in_type = sizeof (float) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
636 * std::numeric_limits<unsigned char>::digits; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
637 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
|
638 DO_BITSHIFT (Float); |
4908 | 639 } |
640 else | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
641 error ("bitshift: not defined for %s objects", cname.c_str ()); |
4908 | 642 |
643 return retval; | |
644 } | |
645 | |
19146
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
646 /* |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
647 %!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
|
648 %!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
|
649 %!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
|
650 %!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
|
651 %!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
|
652 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
653 %!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
|
654 %!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
|
655 %!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
|
656 %!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
|
657 */ |
a84f0182f912
bitfcns.cc: add tests for bitwise operators (some of them failing).
Carnë Draug <carandraug@octave.org>
parents:
18678
diff
changeset
|
658 |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
659 DEFUN (flintmax, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
660 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
661 @deftypefn {} {@var{Imax} =} flintmax () |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
662 @deftypefnx {} {@var{Imax} =} flintmax ("double") |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
663 @deftypefnx {} {@var{Imax} =} flintmax ("single") |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
664 @deftypefnx {} {@var{Imax} =} flintmax (@var{var}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
665 Return the largest integer that can be represented consecutively in a |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
666 floating point value. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
667 |
26057
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
668 The input is either a string specifying a floating point type, or it is an |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
669 existing floating point variable @var{var}. |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
670 |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
671 The default type is @qcode{"double"}, but @qcode{"single"} is a valid option. |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
672 On IEEE 754 compatible systems, @code{flintmax} is @w{@math{2^{53}}} for |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
673 @qcode{"double"} and @w{@math{2^{24}}} for @qcode{"single"}. |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
674 |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
675 Example Code - query an existing variable |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
676 |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
677 @example |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
678 @group |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
679 x = single (1); |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
680 flintmax (x) |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
681 @result{} 16777216 |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
682 @end group |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
683 @end example |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
684 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
685 @seealso{intmax, realmax, realmin} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
686 @end deftypefn */) |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
687 { |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
688 int nargin = args.length (); |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
689 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
690 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
691 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
692 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
693 std::string cname = "double"; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
694 if (nargin == 1) |
26057
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
695 { |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
696 if (args(0).is_string ()) |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
697 cname = args(0).string_value (); |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
698 else if (args(0).isfloat ()) |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
699 cname = args(0).class_name (); |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
700 else |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
701 error ("intmin: argument must be a string or floating point variable"); |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
702 } |
17390
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
703 |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
704 if (cname == "double") |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
705 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
|
706 else if (cname == "single") |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
707 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
|
708 else |
4bcd301754ce
Add Matlab-compatible flintmax function
Mike Miller <mtmiller@ieee.org>
parents:
17389
diff
changeset
|
709 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
|
710 } |
16939
06897f865f0b
Add flintmax() as an alias for function bitmax().
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
711 |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
712 /* |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
713 %!assert (flintmax (), 2^53) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
714 %!assert (flintmax ("double"), 2^53) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
715 %!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
|
716 |
26057
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
717 %!test |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
718 %! x = single (1); |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
719 %! assert (flintmax (x), single (16777216)); |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
720 |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
721 %!error flintmax ("double", 0) |
26057
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
722 %!error <must be a string or floating point variable> flintmax (int8 (1)) |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
723 %!error <not defined for class 'int8'> flintmax ("int8") |
afc3d1da58e5
Expand flintmax to accept a floating point variable as input.
Rik <rik@octave.org>
parents:
26056
diff
changeset
|
724 %!error <not defined for class 'char'> flintmax ("char") |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
725 */ |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
726 |
4915 | 727 DEFUN (intmax, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
728 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
729 @deftypefn {} {@var{Imax} =} intmax () |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
730 @deftypefnx {} {@var{Imax} =} intmax ("@var{type}") |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
731 @deftypefnx {} {@var{Imax} =} intmax (@var{var}) |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
732 Return the largest integer that can be represented by a specific integer type. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
733 |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
734 The input is either a string @qcode{"@var{type}"} specifying an integer type, |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
735 or it is an existing integer variable @var{var}. |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
736 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
737 Possible values for @var{type} are |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
738 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
739 @table @asis |
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
740 @item @qcode{"int8"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
741 signed 8-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
742 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
743 @item @qcode{"int16"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
744 signed 16-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
745 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
746 @item @qcode{"int32"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
747 signed 32-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
748 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
749 @item @qcode{"int64"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
750 signed 64-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
751 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
752 @item @qcode{"uint8"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
753 unsigned 8-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
754 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
755 @item @qcode{"uint16"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
756 unsigned 16-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
757 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
758 @item @qcode{"uint32"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
759 unsigned 32-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
760 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
761 @item @qcode{"uint64"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
762 unsigned 64-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
763 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
764 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
765 The default for @var{type} is @qcode{"int32"}. |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
766 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
767 Example Code - query an existing variable |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
768 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
769 @example |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
770 @group |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
771 x = int8 (1); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
772 intmax (x) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
773 @result{} 127 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
774 @end group |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
775 @end example |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
776 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
777 @seealso{intmin, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
778 @end deftypefn */) |
4908 | 779 { |
4915 | 780 int nargin = args.length (); |
781 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
782 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
783 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
784 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
785 std::string cname = "int32"; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
786 if (nargin == 1) |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
787 { |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
788 if (args(0).is_string ()) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
789 cname = args(0).string_value (); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
790 else if (args(0).isinteger ()) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
791 cname = args(0).class_name (); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
792 else |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
793 error ("intmax: argument must be a string or integer variable"); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
794 } |
4915 | 795 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
796 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
797 |
4915 | 798 if (cname == "uint8") |
5828 | 799 retval = octave_uint8 (std::numeric_limits<uint8_t>::max ()); |
4915 | 800 else if (cname == "uint16") |
5828 | 801 retval = octave_uint16 (std::numeric_limits<uint16_t>::max ()); |
4915 | 802 else if (cname == "uint32") |
5828 | 803 retval = octave_uint32 (std::numeric_limits<uint32_t>::max ()); |
4915 | 804 else if (cname == "uint64") |
5828 | 805 retval = octave_uint64 (std::numeric_limits<uint64_t>::max ()); |
4915 | 806 else if (cname == "int8") |
5828 | 807 retval = octave_int8 (std::numeric_limits<int8_t>::max ()); |
4915 | 808 else if (cname == "int16") |
5828 | 809 retval = octave_int16 (std::numeric_limits<int16_t>::max ()); |
4915 | 810 else if (cname == "int32") |
5828 | 811 retval = octave_int32 (std::numeric_limits<int32_t>::max ()); |
4915 | 812 else if (cname == "int64") |
5828 | 813 retval = octave_int64 (std::numeric_limits<int64_t>::max ()); |
4915 | 814 else |
815 error ("intmax: not defined for '%s' objects", cname.c_str ()); | |
816 | |
817 return retval; | |
818 } | |
819 | |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
820 /* |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
821 %!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
|
822 %!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
|
823 %!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
|
824 %!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
|
825 %!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
|
826 %!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
|
827 %!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
|
828 %!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
|
829 %!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
|
830 |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
831 %!test |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
832 %! x = int8 (1); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
833 %! assert (intmax (x), int8 (127)); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
834 |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
835 %!error intmax ("int32", 0) |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
836 %!error <must be a string or integer variable> intmax (1.0) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
837 %!error <not defined for 'double' objects> intmax ("double") |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
838 %!error <not defined for 'char' objects> intmax ("char") |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
839 */ |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
840 |
4915 | 841 DEFUN (intmin, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
842 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
843 @deftypefn {} {@var{Imin} =} intmin () |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
844 @deftypefnx {} {@var{Imin} =} intmin ("@var{type}") |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
845 @deftypefnx {} {@var{Imin} =} intmin (@var{var}) |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
846 Return the smallest integer that can be represented by a specific integer type. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
847 |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
848 The input is either a string @qcode{"@var{type}"} specifying an integer type, |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
849 or it is an existing integer variable @var{var}. |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
850 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
851 Possible values for @var{type} are |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
852 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
853 @table @asis |
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
854 @item @qcode{"int8"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
855 signed 8-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
856 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
857 @item @qcode{"int16"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
858 signed 16-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
859 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
860 @item @qcode{"int32"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
861 signed 32-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
862 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
863 @item @qcode{"int64"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
864 signed 64-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
865 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
866 @item @qcode{"uint8"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
867 unsigned 8-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
868 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
869 @item @qcode{"uint16"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
870 unsigned 16-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
871 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
872 @item @qcode{"uint32"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
873 unsigned 32-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
874 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
875 @item @qcode{"uint64"} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
876 unsigned 64-bit integer. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
877 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
878 |
26051
aa1064eca173
Improve documentation for intmax/intmin (bug #54866).
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
879 The default for @var{type} is @qcode{"int32"}. |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
880 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
881 Example Code - query an existing variable |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
882 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
883 @example |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
884 @group |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
885 x = int8 (1); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
886 intmin (x) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
887 @result{} -128 |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
888 @end group |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
889 @end example |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
890 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
891 @seealso{intmax, flintmax} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
892 @end deftypefn */) |
4915 | 893 { |
894 int nargin = args.length (); | |
895 | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
896 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
897 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
898 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
899 std::string cname = "int32"; |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
900 if (nargin == 1) |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
901 { |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
902 if (args(0).is_string ()) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
903 cname = args(0).string_value (); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
904 else if (args(0).isinteger ()) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
905 cname = args(0).class_name (); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
906 else |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
907 error ("intmin: argument must be a string or integer variable"); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
908 } |
4915 | 909 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
910 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20870
diff
changeset
|
911 |
4915 | 912 if (cname == "uint8") |
5828 | 913 retval = octave_uint8 (std::numeric_limits<uint8_t>::min ()); |
4915 | 914 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
|
915 retval = octave_uint16 (std::numeric_limits<uint16_t>::min ()); |
4915 | 916 else if (cname == "uint32") |
5828 | 917 retval = octave_uint32 (std::numeric_limits<uint32_t>::min ()); |
4915 | 918 else if (cname == "uint64") |
5828 | 919 retval = octave_uint64 (std::numeric_limits<uint64_t>::min ()); |
4915 | 920 else if (cname == "int8") |
5828 | 921 retval = octave_int8 (std::numeric_limits<int8_t>::min ()); |
4915 | 922 else if (cname == "int16") |
5828 | 923 retval = octave_int16 (std::numeric_limits<int16_t>::min ()); |
4915 | 924 else if (cname == "int32") |
5828 | 925 retval = octave_int32 (std::numeric_limits<int32_t>::min ()); |
4915 | 926 else if (cname == "int64") |
5828 | 927 retval = octave_int64 (std::numeric_limits<int64_t>::min ()); |
4915 | 928 else |
929 error ("intmin: not defined for '%s' objects", cname.c_str ()); | |
930 | |
4908 | 931 return retval; |
932 } | |
10811
e38c071bbc41
allow user query the maximum array size
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
933 |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
934 /* |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
935 %!assert (intmin (), int32 (-2^31)) |
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
936 %!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
|
937 %!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
|
938 %!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
|
939 %!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
|
940 %!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
|
941 %!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
|
942 %!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
|
943 %!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
|
944 |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
945 %!test |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
946 %! x = int8 (1); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
947 %! assert (intmin (x), int8 (-128)); |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
948 |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
949 %!error intmin ("int32", 0) |
26056
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
950 %!error <must be a string or integer variable> intmin (1.0) |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
951 %!error <not defined for 'double' objects> intmin ("double") |
df3f2e119944
Expand intmax/intmin to accept an integer variable as input.
Rik <rik@octave.org>
parents:
26051
diff
changeset
|
952 %!error <not defined for 'char' objects> intmin ("char") |
20870
020b71557b12
2015 Code Sprint: add BIST tests to bitfcns.cc
Mike Miller <mtmiller@octave.org>
parents:
20853
diff
changeset
|
953 */ |
27880
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
954 |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
955 DEFUN (sizemax, args, , |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
956 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
957 @deftypefn {} {@var{max_numel} =} sizemax () |
27880
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
958 Return the largest value allowed for the size of an array. |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
959 |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
960 If Octave is compiled with 64-bit indexing, the result is of class int64, |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
961 otherwise it is of class int32. The maximum array size is slightly smaller |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
962 than the maximum value allowable for the relevant class as reported by |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
963 @code{intmax}. |
27880
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
964 @seealso{intmax} |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
965 @end deftypefn */) |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
966 { |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
967 if (args.length () != 0) |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
968 print_usage (); |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
969 |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
970 return octave_value (octave_int<octave_idx_type> (dim_vector::dim_max ())); |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
971 } |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
972 |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
973 /* |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
974 %!assert (sizemax () >= (intmax ("int32") - 1)) |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
975 |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
976 %!error sizemax (0) |
31b95261c7d2
Backed out changeset 2890a931e647 (bug #47469)
Rik <rik@octave.org>
parents:
27627
diff
changeset
|
977 */ |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
978 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
979 OCTAVE_END_NAMESPACE(octave) |