annotate liboctave/util/oct-inttypes.h @ 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 e7fc6251b698
children aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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: 30489
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 ////////////////////////////////////////////////////////////////////////
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
25
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 19861
diff changeset
26 #if ! defined (octave_oct_inttypes_h)
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17769
diff changeset
27 #define octave_oct_inttypes_h 1
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
28
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
29 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21202
diff changeset
30
23643
3dc16b35ba2c Use round, roundf, roundl from C++ std library.
Rik <rik@octave.org>
parents: 23615
diff changeset
31 #include <cmath>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
32 #include <cstdlib>
6482
7e958a1532c6 [project @ 2007-04-04 02:37:07 by jwe]
jwe
parents: 6402
diff changeset
33
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
34 #include <iosfwd>
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
35 #include <limits>
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
36
4969
52f808101130 [project @ 2004-09-08 02:44:04 by jwe]
jwe
parents: 4968
diff changeset
37 #include "lo-mappers.h"
22073
d18c63a45070 wrappers for setting long double rounding mode (bug #48319)
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
38 #include "lo-traits.h"
30435
1f0a2689cab2 Use forward declarations for octave_int<T> where possible (bug #59820).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30394
diff changeset
39 #include "oct-inttypes-fwd.h"
21785
c9f8a7f7915e use forward declarations instead of including oct-inttypes.h where possible
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
40
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
41 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
42
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
43 OCTAVE_BEGIN_NAMESPACE(octave)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
44
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
45 OCTAVE_BEGIN_NAMESPACE(math)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
46
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
47 inline long double round (long double x)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
48 {
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
49 return std::roundl (x);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
50 }
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
51
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
52 inline long double isnan (long double x)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
53 {
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
54 return isnan (static_cast<double> (x));
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
55 }
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
56
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
57 OCTAVE_END_NAMESPACE(math)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
58 OCTAVE_END_NAMESPACE(octave)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
59
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
60 #endif
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
61
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
62 // FIXME: we define this by our own because some compilers, such as
8333
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8319
diff changeset
63 // MSVC, do not provide std::abs (int64_t) and std::abs (uint64_t). In
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8319
diff changeset
64 // the future, it should go away in favor of std::abs.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
65
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
66 template <typename T>
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
67 inline T
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
68 octave_int_abs (T x)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
69 {
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
70 return (x >= 0 ? x : -x);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
71 }
8293
ad5bb02d267a workaround missing std::abs(int64_t) in MSVC
Jaroslav Hajek <highegg@gmail.com>
parents: 8202
diff changeset
72
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
73 // Query for an integer type of certain sizeof, and signedness.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
74
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
75 template <int qsize, bool qsigned>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
76 struct query_integer_type
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
77 {
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
78 public:
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
79
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
80 static const bool registered = false;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
81
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
82 // Void shall result in a compile-time error if we attempt to use it
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
83 // in computations.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
84
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
85 typedef void type;
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
86 };
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
87
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
88 #define OCTAVE_REGISTER_INT_TYPE(TYPE) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
89 template <> \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
90 class query_integer_type<sizeof (TYPE), \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
91 std::numeric_limits<TYPE>::is_signed> \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
92 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
93 public: \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
94 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
95 static const bool registered = true; \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
96 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
97 typedef TYPE type; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
98 }
7596
6929e40fc597 compatible handling of NaN -> int conversions
John W. Eaton <jwe@octave.org>
parents: 7534
diff changeset
99
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
100 // No two registered integers can share sizeof and signedness.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
101 OCTAVE_REGISTER_INT_TYPE (int8_t);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
102 OCTAVE_REGISTER_INT_TYPE (uint8_t);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
103 OCTAVE_REGISTER_INT_TYPE (int16_t);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
104 OCTAVE_REGISTER_INT_TYPE (uint16_t);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
105 OCTAVE_REGISTER_INT_TYPE (int32_t);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
106 OCTAVE_REGISTER_INT_TYPE (uint32_t);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
107 OCTAVE_REGISTER_INT_TYPE (int64_t);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
108 OCTAVE_REGISTER_INT_TYPE (uint64_t);
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
109
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
110 #undef OCTAVE_REGISTER_INT_TYPE
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
111
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
112 // Handles non-homogeneous integer comparisons. Avoids doing useless
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
113 // tests.
4943
1a499d0c58f5 [project @ 2004-08-31 00:51:31 by jwe]
jwe
parents: 4920
diff changeset
114
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
115 class octave_int_cmp_op
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
116 {
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
117 // This determines a suitable promotion type for T1 when meeting T2
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
118 // in a binary relation. If promotion to int or T2 is safe, it is
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
119 // used. Otherwise, the signedness of T1 is preserved and it is
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
120 // widened if T2 is wider. Notice that if this is applied to both
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
121 // types, they must end up with equal size.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
122
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
123 template <typename T1, typename T2>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
124 class prom
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
125 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
126 // Promote to int?
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
127 static const bool pint = (sizeof (T1) < sizeof (int)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
128 && sizeof (T2) < sizeof (int));
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
129
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
130 static const bool t1sig = std::numeric_limits<T1>::is_signed;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
131 static const bool t2sig = std::numeric_limits<T2>::is_signed;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
132
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
133 static const bool psig
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
134 = (pint || (sizeof (T2) > sizeof (T1) && t2sig) || t1sig);
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
135
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
136 static const int psize
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
137 = (pint
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
138 ? sizeof (int)
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
139 : (sizeof (T2) > sizeof (T1) ? sizeof (T2) : sizeof (T1)));
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
140 public:
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
141
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
142 typedef typename query_integer_type<psize, psig>::type type;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
143 };
4943
1a499d0c58f5 [project @ 2004-08-31 00:51:31 by jwe]
jwe
parents: 4920
diff changeset
144
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
145 // Implements comparisons between two types of equal size but
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
146 // possibly different signedness.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
147
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
148 template <typename xop, int size>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
149 class uiop
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
150 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
151 typedef typename query_integer_type<size, false>::type utype;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
152 typedef typename query_integer_type<size, true>::type stype;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
153
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
154 public:
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
155
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
156 static bool op (utype x, utype y)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
157 {
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
158 return xop::op (x, y);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
159 }
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
160
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
161 static bool op (stype x, stype y)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
162 {
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
163 return xop::op (x, y);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
164 }
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
165
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
166 static bool op (stype x, utype y)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
167 {
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
168 return (x < 0) ? xop::ltval : xop::op (static_cast<utype> (x), y);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
169 }
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
170
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
171 static bool op (utype x, stype y)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
172 {
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
173 return (y < 0) ? xop::gtval : xop::op (x, static_cast<utype> (y));
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
174 }
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
175 };
4943
1a499d0c58f5 [project @ 2004-08-31 00:51:31 by jwe]
jwe
parents: 4920
diff changeset
176
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
177 public:
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
178
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
179 // Rationale: Comparators have a single static method, rel(), that
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
180 // returns the result of the binary relation. They also have two
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
181 // static boolean fields: ltval, gtval determine the value of x OP y
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
182 // if x < y, x > y, respectively.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
183
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
184 #define OCTAVE_REGISTER_INT_CMP_OP(NM, OP) \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
185 class NM \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
186 { \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
187 public: \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
188 \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
189 static const bool ltval = (0 OP 1); \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
190 static const bool gtval = (1 OP 0); \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
191 \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
192 template <typename T> \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
193 static bool op (T x, T y) { return x OP y; } \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
194 }
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
195
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
196 OCTAVE_REGISTER_INT_CMP_OP (lt, <);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
197 OCTAVE_REGISTER_INT_CMP_OP (le, <=);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
198 OCTAVE_REGISTER_INT_CMP_OP (gt, >);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
199 OCTAVE_REGISTER_INT_CMP_OP (ge, >=);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
200 OCTAVE_REGISTER_INT_CMP_OP (eq, ==);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
201 OCTAVE_REGISTER_INT_CMP_OP (ne, !=);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
202
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
203 #undef OCTAVE_REGISTER_INT_CMP_OP
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
204
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
205 // We also provide two special relations: ct, yielding always true,
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
206 // and cf, yielding always false.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
207
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
208 #define OCTAVE_REGISTER_INT_CONST_OP(NM, VALUE) \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
209 class NM \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
210 { \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
211 public: \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
212 \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
213 static const bool ltval = VALUE; \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
214 static const bool gtval = VALUE; \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
215 \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
216 template <typename T> \
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
217 static bool op (T, T) { return VALUE; } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
218 }
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
219
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
220 OCTAVE_REGISTER_INT_CONST_OP (ct, true);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
221 OCTAVE_REGISTER_INT_CONST_OP (cf, false);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
222
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
223 #undef OCTAVE_REGISTER_INT_CONST_OP
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
224
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
225 // Universal comparison operation.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
226
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
227 template <typename xop, typename T1, typename T2>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
228 static bool
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
229 op (T1 x, T2 y)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
230 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
231 typedef typename prom<T1, T2>::type PT1;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
232 typedef typename prom<T2, T1>::type PT2;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
233
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
234 return uiop<xop, sizeof (PT1)>::op (static_cast<PT1> (x),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
235 static_cast<PT2> (y));
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
236 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
237
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
238 public:
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
239
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
240 // Mixed comparisons.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
241
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
242 template <typename xop, typename T>
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
243 static bool mop (T x, double y)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
244 {
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
245 return xop::op (static_cast<double> (x), y);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
246 }
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
247
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
248 template <typename xop, typename T>
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
249 static bool mop (double x, T y)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
250 {
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
251 return xop::op (x, static_cast<double> (y));
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
252 }
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
253
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
254 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
255
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
256 # define OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_CMP_OPS(T) \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
257 template <typename xop> \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
258 static OCTAVE_API bool external_mop (double, T); \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
259 \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
260 template <typename xop> \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
261 static OCTAVE_API bool external_mop (T, double)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
262
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
263 OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_CMP_OPS (int64_t);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
264 OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_CMP_OPS (uint64_t);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
265
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
266 #endif
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
267
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
268 // Typecasting to doubles won't work properly for 64-bit integers --
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
269 // they lose precision. If we have long doubles, use them...
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
270
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
271 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
272
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
273 # if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
274
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
275 # define OCTAVE_DEFINE_LONG_DOUBLE_INT_CMP_OP(T) \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
276 template <typename xop> \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
277 static bool mop (double x, T y) \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
278 { \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
279 return external_mop<xop> (x, y); \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
280 } \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
281 \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
282 template <typename xop> \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
283 static bool mop (T x, double y) \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
284 { \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
285 return external_mop<xop> (x, y); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
286 }
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
287
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21139
diff changeset
288 # else
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
289
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
290 # define OCTAVE_DEFINE_LONG_DOUBLE_INT_CMP_OP(T) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
291 template <typename xop> \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
292 static bool mop (double x, T y) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
293 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
294 return xop::op (static_cast<long double> (x), \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
295 static_cast<long double> (y)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
296 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
297 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
298 template <typename xop> \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
299 static bool mop (T x, double y) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
300 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
301 return xop::op (static_cast<long double> (x), \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
302 static_cast<long double> (y)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
303 }
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
304
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21139
diff changeset
305 # endif
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
306
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
307 #else
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
308
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8731
diff changeset
309 // ... otherwise, use external handlers
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8731
diff changeset
310
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
311 // FIXME: We could declare directly the mop methods as external, but
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
312 // we can't do this because bugs in gcc (<= 4.3) prevent explicit
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
313 // instantiations later in that case.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
314
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
315 # define OCTAVE_DEFINE_LONG_DOUBLE_INT_CMP_OP(T) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
316 template <typename xop> \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
317 static OCTAVE_API bool emulate_mop (double, T); \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
318 \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
319 template <typename xop> \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
320 static bool mop (double x, T y) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
321 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
322 return emulate_mop<xop> (x, y); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
323 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
324 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
325 template <typename xop> \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
326 static OCTAVE_API bool emulate_mop (T, double); \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
327 \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
328 template <typename xop> \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
329 static bool mop (T x, double y) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
330 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
331 return emulate_mop<xop> (x, y); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
332 }
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
333
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8731
diff changeset
334 #endif
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8731
diff changeset
335
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
336 OCTAVE_DEFINE_LONG_DOUBLE_INT_CMP_OP (int64_t)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
337 OCTAVE_DEFINE_LONG_DOUBLE_INT_CMP_OP (uint64_t)
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8731
diff changeset
338
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
339 #undef OCTAVE_DEFINE_LONG_DOUBLE_INT_CMP_OP
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
340 };
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
341
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
342 // Base integer class. No data, just conversion methods and exception
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
343 // flags.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
344
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
345 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
346 class octave_int_base
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
347 {
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
348 public:
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
349
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
350 static T min_val (void) { return std::numeric_limits<T>::min (); }
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
351 static T max_val (void) { return std::numeric_limits<T>::max (); }
4943
1a499d0c58f5 [project @ 2004-08-31 00:51:31 by jwe]
jwe
parents: 4920
diff changeset
352
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
353 // Convert integer value.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
354
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
355 template <typename S>
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
356 static T truncate_int (const S& value)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
357 {
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
358 // An exhaustive test whether the max and/or min check can be
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
359 // omitted.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
360
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
361 static const bool t_is_signed = std::numeric_limits<T>::is_signed;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
362 static const bool s_is_signed = std::numeric_limits<S>::is_signed;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
363
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
364 static const int t_size = sizeof (T);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
365 static const int s_size = sizeof (S);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
366
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
367 static const bool omit_chk_min
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
368 = (! s_is_signed || (t_is_signed && t_size >= s_size));
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
369
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
370 static const bool omit_chk_max
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
371 = (t_size > s_size
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
372 || (t_size == s_size && (! t_is_signed || s_is_signed)));
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
373
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
374 // If the check can be omitted, substitute constant false
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
375 // relation.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
376
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
377 typedef octave_int_cmp_op::cf cf;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
378 typedef octave_int_cmp_op::lt lt;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
379 typedef octave_int_cmp_op::gt gt;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
380 typedef typename if_then_else<omit_chk_min, cf, lt>::result chk_min;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
381 typedef typename if_then_else<omit_chk_max, cf, gt>::result chk_max;
4943
1a499d0c58f5 [project @ 2004-08-31 00:51:31 by jwe]
jwe
parents: 4920
diff changeset
382
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
383 // Efficiency of the following depends on inlining and dead code
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
384 // elimination, but that should be a piece of cake for most
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
385 // compilers.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
386
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
387 if (chk_min::op (value, static_cast<S> (min_val ())))
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
388 return min_val ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
389 else if (chk_max::op (value, static_cast<S> (max_val ())))
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
390 return max_val ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
391 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
392 return static_cast<T> (value);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
393 }
4943
1a499d0c58f5 [project @ 2004-08-31 00:51:31 by jwe]
jwe
parents: 4920
diff changeset
394
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
395 private:
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
396
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
397 // Compute a real-valued threshold for a max/min check.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
398
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
399 template <typename S>
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
400 static S compute_threshold (S val, T orig_val)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
401 {
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
402 // Fool optimizations (maybe redundant).
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
403
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
404 val = octave::math::round (val);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
405
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
406 // If val is even, but orig_val is odd, we're one unit off.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
407
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
408 if (orig_val % 2 && val / 2 == octave::math::round (val / 2))
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
409 // FIXME: is this always correct?
19739
3fa35defe495 Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
410 val *= (static_cast<S> (1) - (std::numeric_limits<S>::epsilon () / 2));
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
411
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
412 return val;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
413 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
414
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
415 public:
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21235
diff changeset
416
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
417 // Convert a real number (check NaN and non-int).
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
418
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
419 template <typename S>
29230
6b3faa844395 Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28645
diff changeset
420 static OCTAVE_API T convert_real (const S& value);
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
421 };
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
422
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
423 // Saturated (homogeneous) integer arithmetics. The signed and
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
424 // unsigned implementations are significantly different, so we
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
425 // implement another layer and completely specialize. Arithmetics
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
426 // inherits from octave_int_base so that it can use its exceptions and
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
427 // truncation functions.
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
428
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
429 template <typename T, bool is_signed>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
430 class octave_int_arith_base
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
431 { };
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
432
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
433 // Unsigned arithmetics. C++ standard requires it to be modular, so
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
434 // the overflows can be handled efficiently and reliably.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
435
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
436 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
437 class octave_int_arith_base<T, false> : octave_int_base<T>
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
438 {
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
439 public:
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
440
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
441 static T abs (T x) { return x; }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
442
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
443 static T signum (T x) { return x ? static_cast<T> (1) : static_cast<T> (0); }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
444
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
445 // Shifts do not overflow.
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
446
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
447 static T rshift (T x, int n) { return x >> n; }
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
448
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
449 static T lshift (T x, int n) { return x << n; }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
450
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
451 static T minus (T) { return static_cast<T> (0); }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
452
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
453 // The overflow behavior for unsigned integers is guaranteed by
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
454 // C and C++, so the following should always work.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
455
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
456 static T add (T x, T y)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
457 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
458 T u = x + y;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
459
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
460 if (u < x)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
461 u = octave_int_base<T>::max_val ();
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
462
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
463 return u;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
464 }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
465
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
466 static T sub (T x, T y)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
467 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
468 T u = x - y;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
469
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
470 if (u > x)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
471 u = 0;
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
472
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
473 return u;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
474 }
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
475
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
476 // Multiplication is done using promotion to wider integer type. If
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
477 // there is no suitable promotion type, this operation *MUST* be
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
478 // specialized.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
479
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
480 static T mul (T x, T y) { return mul_internal (x, y); }
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
481
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
482 static T mul_internal (T x, T y)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
483 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
484 // Promotion type for multiplication (if exists).
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
485
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
486 typedef typename query_integer_type<2*sizeof (T), false>::type mptype;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
487
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
488 return octave_int_base<T>::truncate_int (static_cast<mptype> (x)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
489 * static_cast<mptype> (y));
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
490 }
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
491
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
492 // Division with rounding to nearest. Note that / and % are
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
493 // probably computed by a single instruction.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
494
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
495 static T div (T x, T y)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
496 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
497 if (y != 0)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
498 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
499 T z = x / y;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
500 T w = x % y;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
501
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
502 if (w >= y-w)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
503 z += 1;
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
504
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
505 return z;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
506 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
507 else
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
508 return x ? octave_int_base<T>::max_val () : 0;
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
509 }
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
510
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
511 // Remainder.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
512
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
513 static T rem (T x, T y) { return y != 0 ? x % y : 0; }
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
514
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
515 // Modulus. Note the weird y = 0 case for Matlab compatibility.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
516
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
517 static T mod (T x, T y) { return y != 0 ? x % y : x; }
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
518 };
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
519
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
520 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
521
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
522 // Handle 64-bit multiply using long double.
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
523
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
524 # if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
525
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
526 extern OCTAVE_API uint64_t
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
527 octave_external_uint64_uint64_mul (uint64_t, uint64_t);
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
528
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
529 # endif
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
530
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
531 template <>
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
532 inline uint64_t
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
533 octave_int_arith_base<uint64_t, false>::mul_internal (uint64_t x, uint64_t y)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
534 {
17980
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
535 uint64_t retval;
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
536
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
537 long double p = static_cast<long double> (x) * static_cast<long double> (y);
17980
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
538
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
539 if (p > static_cast<long double> (octave_int_base<uint64_t>::max_val ()))
17980
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
540 retval = octave_int_base<uint64_t>::max_val ();
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
541 else
17980
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
542 retval = static_cast<uint64_t> (p);
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
543
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
544 return retval;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
545 }
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
546
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
547 template <>
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
548 inline uint64_t
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
549 octave_int_arith_base<uint64_t, false>::mul (uint64_t x, uint64_t y)
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
550 {
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
551 # if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
552 return octave_external_uint64_uint64_mul (x, y);
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
553 # else
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
554 return mul_internal (x, y);
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
555 # endif
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
556 }
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
557
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
558 #else
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
559
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
560 // Special handler for 64-bit integer multiply.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
561
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
562 template <>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
563 OCTAVE_API uint64_t
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
564 octave_int_arith_base<uint64_t, false>::mul_internal (uint64_t, uint64_t);
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
565
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
566 #endif
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
567
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
568 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
569 class octave_int_arith_base<T, true> : octave_int_base<T>
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
570 {
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
571 // The corresponding unsigned type.
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
572 typedef typename query_integer_type<sizeof (T), false>::type UT;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
573
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
574 public:
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
575
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
576 // Returns 1 for negative number, 0 otherwise.
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
577
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
578 static T __signbit (T x) { return (x < 0) ? 1 : 0; }
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
579
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
580 static T abs (T x)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
581 {
25843
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
582 // -INT_MAX is safe because C++ actually allows only three
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
583 // implementations of integers: sign & magnitude, ones complement
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
584 // and twos complement. The first test will, with modest
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
585 // optimizations, evaluate at compile time, and maybe eliminate
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
586 // the branch completely.
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
587
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
588 return ((octave_int_base<T>::min_val () < -octave_int_base<T>::max_val ()
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
589 && x == octave_int_base<T>::min_val ())
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
590 ? octave_int_base<T>::max_val ()
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
591 : ((x < 0) ? -x : x));
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
592 }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
593
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
594 static T signum (T x)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
595 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
596 // With modest optimizations, this will compile without a jump.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
597
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
598 return ((x > 0) ? 1 : 0) - __signbit (x);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
599 }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
600
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
601 // FIXME: we do not have an authority what signed shifts should
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
602 // exactly do, so we define them the easy way. Note that Matlab
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
603 // does not define signed shifts.
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
604
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
605 static T rshift (T x, int n) { return x >> n; }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
606
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
607 static T lshift (T x, int n) { return x << n; }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
608
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
609 // Minus has problems similar to abs.
25843
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
610
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
611 static T minus (T x)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
612 {
25843
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
613 return ((octave_int_base<T>::min_val () < -octave_int_base<T>::max_val ()
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
614 && x == octave_int_base<T>::min_val ())
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
615 ? octave_int_base<T>::max_val ()
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
616 : -x);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
617 }
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
618
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
619 static T add (T x, T y)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
620 {
25843
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
621 // Avoid anything that may overflow.
25838
26c41d8bf170 fix min-val saturation for 64-bit integer addition (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
622
25843
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
623 return (y < 0
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
624 ? (x < octave_int_base<T>::min_val () - y
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
625 ? octave_int_base<T>::min_val ()
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
626 : x + y)
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
627 : (x > octave_int_base<T>::max_val () - y
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
628 ? octave_int_base<T>::max_val ()
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
629 : x + y));
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
630 }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
631
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
632 static T sub (T x, T y)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
633 {
25843
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
634 // Avoid anything that may overflow.
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
635
25843
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
636 return (y < 0
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
637 ? (x > octave_int_base<T>::max_val () + y
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
638 ? octave_int_base<T>::max_val ()
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
639 : x - y)
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
640 : (x < octave_int_base<T>::min_val () + y
27933
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
641 ? octave_int_base<T>::min_val ()
25843
144820478378 eliminate OCTAVE_HAVE_FAST_INT_OPS macro and associated code (bug #54572)
John W. Eaton <jwe@octave.org>
parents: 25838
diff changeset
642 : x - y));
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
643 }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
644
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
645 // Multiplication is done using promotion to wider integer type. If
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
646 // there is no suitable promotion type, this operation *MUST* be
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
647 // specialized.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
648
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
649 static T mul (T x, T y) { return mul_internal (x, y); }
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
650
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
651 static T mul_internal (T x, T y)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
652 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
653 // Promotion type for multiplication (if exists).
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
654
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
655 typedef typename query_integer_type<2*sizeof (T), true>::type mptype;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
656
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
657 return octave_int_base<T>::truncate_int (static_cast<mptype> (x)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
658 * static_cast<mptype> (y));
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
659 }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
660
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
661 // Division.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
662
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
663 static T div (T x, T y)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
664 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
665 T z;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
666
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
667 if (y == 0)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
668 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
669 if (x < 0)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
670 z = octave_int_base<T>::min_val ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
671 else if (x != 0)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
672 z = octave_int_base<T>::max_val ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
673 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
674 z = 0;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
675 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
676 else if (y < 0)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
677 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
678 // This is a special case that overflows as well.
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
679 if (y == -1 && x == octave_int_base<T>::min_val ())
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
680 z = octave_int_base<T>::max_val ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
681 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
682 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
683 z = x / y;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
684 // Can't overflow, but std::abs (x) can!
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
685 T w = -octave_int_abs (x % y);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
686 if (w <= y - w)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
687 z -= 1 - (__signbit (x) << 1);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
688 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
689 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
690 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
691 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
692 z = x / y;
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
693
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
694 // FIXME: this is a workaround due to MSVC's absence of
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
695 // std::abs (int64_t). The call to octave_int_abs can't
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
696 // overflow, but std::abs (x) can!
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
697 T w = octave_int_abs (x % y);
8333
9238637cb81c style fixes
John W. Eaton <jwe@octave.org>
parents: 8319
diff changeset
698
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
699 if (w >= y - w)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
700 z += 1 - (__signbit (x) << 1);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
701 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
702 return z;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
703 }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
704
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
705 // Remainder.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
706
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
707 static T rem (T x, T y)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
708 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
709 return y != 0 ? x % y : 0;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
710 }
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
711
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
712 // Modulus. Note the weird y = 0 case for Matlab compatibility.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
713
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
714 static T mod (T x, T y)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
715 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
716 if (y != 0)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
717 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
718 T r = x % y;
25858
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25843
diff changeset
719 return (r == 0) ? 0 : (((r < 0) != (y < 0)) ? r + y : r);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
720 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
721 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
722 return x;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
723 }
7521
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
724 };
6f10bbb2854a avoid some GCC warnings for unsigned comparisons
John W. Eaton <jwe@octave.org>
parents: 7503
diff changeset
725
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
726 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
727
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
728 // Handle 64-bit multiply using long double
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
729
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
730 # if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
731
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
732 extern OCTAVE_API int64_t
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
733 octave_external_int64_int64_mul (int64_t, int64_t);
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
734
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
735 # endif
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
736
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
737 template <>
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
738 inline int64_t
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
739 octave_int_arith_base<int64_t, true>::mul_internal (int64_t x, int64_t y)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
740 {
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
741 int64_t retval;
17980
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
742
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
743 long double p = static_cast<long double> (x) * static_cast<long double> (y);
17980
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
744
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
745 if (p > static_cast<long double> (octave_int_base<int64_t>::max_val ()))
17980
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
746 retval = octave_int_base<int64_t>::max_val ();
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
747 else if (p < static_cast<long double> (octave_int_base<int64_t>::min_val ()))
17980
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
748 retval = octave_int_base<int64_t>::min_val ();
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
749 else
17980
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
750 retval = static_cast<int64_t> (p);
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
751
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
752 return retval;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
753 }
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
754
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
755 template <>
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
756 inline int64_t
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
757 octave_int_arith_base<int64_t, true>::mul (int64_t x, int64_t y)
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
758 {
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
759 # if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
760 return octave_external_int64_int64_mul (x, y);
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
761 # else
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
762 return mul_internal (x, y);
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
763 # endif
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
764 }
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
765
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
766 #else
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
767
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
768 // Special handler for 64-bit integer multiply.
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
769
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
770 template <>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
771 OCTAVE_API int64_t
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
772 octave_int_arith_base<int64_t, true>::mul_internal (int64_t, int64_t);
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
773
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
774 #endif
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
775
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
776 // This class simply selects the proper arithmetics.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
777 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
778 class octave_int_arith
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30232
diff changeset
779 : public octave_int_arith_base<T, std::numeric_limits<T>::is_signed>
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
780 { };
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
781
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
782 template <typename T>
31400
e7fc6251b698 Use more specialized API flags for template classes (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31160
diff changeset
783 class
e7fc6251b698 Use more specialized API flags for template classes (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31160
diff changeset
784 OCTAVE_TEMPLATE_API
e7fc6251b698 Use more specialized API flags for template classes (bug #61711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31160
diff changeset
785 octave_int : public octave_int_base<T>
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
786 {
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
787 public:
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
788
4943
1a499d0c58f5 [project @ 2004-08-31 00:51:31 by jwe]
jwe
parents: 4920
diff changeset
789 typedef T val_type;
1a499d0c58f5 [project @ 2004-08-31 00:51:31 by jwe]
jwe
parents: 4920
diff changeset
790
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
791 octave_int (void) : m_ival () { }
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
792
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
793 octave_int (T i) : m_ival (i) { }
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
794
21354
06d15e4e611a move public data type macros to octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21308
diff changeset
795 #if defined (OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
796
18627
37c300acfcfd don't truncate when casting char to uintN values (bug #42054)
John W. Eaton <jwe@octave.org>
parents: 18252
diff changeset
797 // Always treat characters as unsigned.
37c300acfcfd don't truncate when casting char to uintN values (bug #42054)
John W. Eaton <jwe@octave.org>
parents: 18252
diff changeset
798 octave_int (char c)
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
799 : m_ival (octave_int_base<T>::truncate_int (static_cast<unsigned char> (c)))
18627
37c300acfcfd don't truncate when casting char to uintN values (bug #42054)
John W. Eaton <jwe@octave.org>
parents: 18252
diff changeset
800 { }
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
801
21235
b48d65c5df5b Disable char/int8_t function overloads where not permitted (bug #45411)
Mike Miller <mtmiller@octave.org>
parents: 19861
diff changeset
802 #endif
18627
37c300acfcfd don't truncate when casting char to uintN values (bug #42054)
John W. Eaton <jwe@octave.org>
parents: 18252
diff changeset
803
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
804 octave_int (double d)
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
805 : m_ival (octave_int_base<T>::convert_real (d)) { }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
806
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
807 octave_int (float d)
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
808 : m_ival (octave_int_base<T>::convert_real (d)) { }
6402
fe9817a6ee98 [project @ 2007-03-13 02:25:31 by jwe]
jwe
parents: 6108
diff changeset
809
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
810 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
811
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
812 octave_int (long double d)
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
813 : m_ival (octave_int_base<T>::convert_real (d)) { }
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
814
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
815 #endif
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
816
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
817 octave_int (bool b) : m_ival (b) { }
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
818
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
819 template <typename U>
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
820 octave_int (const U& i)
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
821 : m_ival(octave_int_base<T>::truncate_int (i)) { }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
822
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
823 template <typename U>
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
824 octave_int (const octave_int<U>& i)
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
825 : m_ival (octave_int_base<T>::truncate_int (i.value ())) { }
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
826
27381
d4fdaeaab7f3 use default or deleted ctors/dtors/assignment ops in liboctave/util
John W. Eaton <jwe@octave.org>
parents: 27379
diff changeset
827 octave_int (const octave_int<T>&) = default;
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
828
27381
d4fdaeaab7f3 use default or deleted ctors/dtors/assignment ops in liboctave/util
John W. Eaton <jwe@octave.org>
parents: 27379
diff changeset
829 octave_int& operator = (const octave_int<T>&) = default;
d4fdaeaab7f3 use default or deleted ctors/dtors/assignment ops in liboctave/util
John W. Eaton <jwe@octave.org>
parents: 27379
diff changeset
830
d4fdaeaab7f3 use default or deleted ctors/dtors/assignment ops in liboctave/util
John W. Eaton <jwe@octave.org>
parents: 27379
diff changeset
831 ~octave_int (void) = default;
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
832
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
833 T value (void) const { return m_ival; }
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
834
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4943
diff changeset
835 const unsigned char * iptr (void) const
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
836 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
837 return reinterpret_cast<const unsigned char *> (& m_ival);
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
838 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4943
diff changeset
839
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
840 bool operator ! (void) const { return ! m_ival; }
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
841
7198
4555c116b420 [project @ 2007-11-27 03:06:10 by jwe]
jwe
parents: 7177
diff changeset
842 bool bool_value (void) const { return static_cast<bool> (value ()); }
4555c116b420 [project @ 2007-11-27 03:06:10 by jwe]
jwe
parents: 7177
diff changeset
843
4555c116b420 [project @ 2007-11-27 03:06:10 by jwe]
jwe
parents: 7177
diff changeset
844 char char_value (void) const { return static_cast<char> (value ()); }
4555c116b420 [project @ 2007-11-27 03:06:10 by jwe]
jwe
parents: 7177
diff changeset
845
4555c116b420 [project @ 2007-11-27 03:06:10 by jwe]
jwe
parents: 7177
diff changeset
846 double double_value (void) const { return static_cast<double> (value ()); }
4555c116b420 [project @ 2007-11-27 03:06:10 by jwe]
jwe
parents: 7177
diff changeset
847
4555c116b420 [project @ 2007-11-27 03:06:10 by jwe]
jwe
parents: 7177
diff changeset
848 float float_value (void) const { return static_cast<float> (value ()); }
4555c116b420 [project @ 2007-11-27 03:06:10 by jwe]
jwe
parents: 7177
diff changeset
849
7177
57d2546ad8d5 [project @ 2007-11-14 22:21:35 by jwe]
jwe
parents: 7017
diff changeset
850 operator T (void) const { return value (); }
57d2546ad8d5 [project @ 2007-11-14 22:21:35 by jwe]
jwe
parents: 7017
diff changeset
851
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
852 octave_int<T> operator + () const { return *this; }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
853
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
854 // unary operators & mappers
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
855 #define OCTAVE_INT_UN_OP(OPNAME, NAME) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
856 inline octave_int<T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
857 OPNAME () const \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
858 { \
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
859 return octave_int_arith<T>::NAME (m_ival); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
860 }
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
861
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
862 OCTAVE_INT_UN_OP (operator -, minus)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
863 OCTAVE_INT_UN_OP (abs, abs)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
864 OCTAVE_INT_UN_OP (signum, signum)
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
865
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
866 #undef OCTAVE_INT_UN_OP
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
867
31160
4efd735d034c octave_int<T>: Overload operator ~ ().
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
868 octave_int<T> operator ~ (void) const
4efd735d034c octave_int<T>: Overload operator ~ ().
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
869 {
4efd735d034c octave_int<T>: Overload operator ~ ().
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
870 T bitinv = ~ m_ival;
4efd735d034c octave_int<T>: Overload operator ~ ().
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
871 return bitinv;
4efd735d034c octave_int<T>: Overload operator ~ ().
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
872 }
4efd735d034c octave_int<T>: Overload operator ~ ().
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
873
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
874 // Homogeneous binary integer operations.
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
875 #define OCTAVE_INT_BIN_OP(OP, NAME, ARGT) \
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
876 inline octave_int<T> \
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
877 operator OP (const ARGT& y) const \
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
878 { \
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
879 return octave_int_arith<T>::NAME (m_ival, y); \
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
880 } \
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
881 \
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
882 inline octave_int<T>& \
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
883 operator OP##= (const ARGT& y) \
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
884 { \
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
885 m_ival = octave_int_arith<T>::NAME (m_ival, y); \
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
886 return *this; \
4952
bfd57b466752 [project @ 2004-09-01 00:49:05 by jwe]
jwe
parents: 4949
diff changeset
887 }
bfd57b466752 [project @ 2004-09-01 00:49:05 by jwe]
jwe
parents: 4949
diff changeset
888
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
889 OCTAVE_INT_BIN_OP (+, add, octave_int<T>)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
890 OCTAVE_INT_BIN_OP (-, sub, octave_int<T>)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
891 OCTAVE_INT_BIN_OP (*, mul, octave_int<T>)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
892 OCTAVE_INT_BIN_OP (/, div, octave_int<T>)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
893 OCTAVE_INT_BIN_OP (%, rem, octave_int<T>)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
894 OCTAVE_INT_BIN_OP (<<, lshift, int)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
895 OCTAVE_INT_BIN_OP (>>, rshift, int)
4952
bfd57b466752 [project @ 2004-09-01 00:49:05 by jwe]
jwe
parents: 4949
diff changeset
896
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
897 #undef OCTAVE_INT_BIN_OP
7503
8c32f95c2639 convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents: 7198
diff changeset
898
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
899 static octave_int<T> min (void) { return std::numeric_limits<T>::min (); }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
900 static octave_int<T> max (void) { return std::numeric_limits<T>::max (); }
4906
6754342ef7ad [project @ 2004-06-23 11:11:50 by jwe]
jwe
parents: 4902
diff changeset
901
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
902 static int nbits (void) { return std::numeric_limits<T>::digits; }
4909
5c9e36402f17 [project @ 2004-07-12 17:08:24 by jwe]
jwe
parents: 4906
diff changeset
903
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14168
diff changeset
904 static int byte_size (void) { return sizeof (T); }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4943
diff changeset
905
29230
6b3faa844395 Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28645
diff changeset
906 static const OCTAVE_API char * type_name ();
7997
2b8952e133c9 implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
907
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
908 // The following are provided for convenience.
30037
8d6bdd961494 maint: use "s_" prefix for static class variables in oct-inttypes.h
Rik <rik@octave.org>
parents: 29359
diff changeset
909 static const octave_int s_zero, s_one;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
910
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
911 private:
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
912
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
913 T m_ival;
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
914 };
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
915
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
916 template <typename T>
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
917 inline octave_int<T>
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
918 rem (const octave_int<T>& x, const octave_int<T>& y)
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
919 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
920 return octave_int_arith<T>::rem (x.value (), y.value ());
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
921 }
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
922
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
923 template <typename T>
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
924 inline octave_int<T>
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
925 mod (const octave_int<T>& x, const octave_int<T>& y)
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
926 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
927 return octave_int_arith<T>::mod (x.value (), y.value ());
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
928 }
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
929
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
930 // No mixed integer binary operations!
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
931
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
932 OCTAVE_BEGIN_NAMESPACE(octave)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
933
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
934 OCTAVE_BEGIN_NAMESPACE(math)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
935
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
936 template <typename T>
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
937 bool
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
938 isnan (const octave_int<T>&)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
939 {
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
940 return false;
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
941 }
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
942
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
943 OCTAVE_END_NAMESPACE(math)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31400
diff changeset
944 OCTAVE_END_NAMESPACE(octave)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
945
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
946 // FIXME: can/should any of these be inline?
7997
2b8952e133c9 implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
947
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
948 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
949 extern OCTAVE_API octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
950 pow (const octave_int<T>&, const octave_int<T>&);
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
951
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
952 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
953 extern OCTAVE_API octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
954 pow (const double& a, const octave_int<T>& b);
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
955
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
956 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
957 extern OCTAVE_API octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
958 pow (const octave_int<T>& a, const double& b);
7922
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7789
diff changeset
959
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
960 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
961 extern OCTAVE_API octave_int<T>
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
962 pow (const float& a, const octave_int<T>& b);
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
963
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
964 template <typename T>
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
965 extern OCTAVE_API octave_int<T>
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
966 pow (const octave_int<T>& a, const float& b);
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
967
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
968 // FIXME: Do we really need a differently named single-precision
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
969 // function integer power function here instead of an overloaded
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
970 // one?
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
971
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
972 template <typename T>
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
973 extern OCTAVE_API octave_int<T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
974 powf (const float& a, const octave_int<T>& b);
4952
bfd57b466752 [project @ 2004-09-01 00:49:05 by jwe]
jwe
parents: 4949
diff changeset
975
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
976 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
977 extern OCTAVE_API octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
978 powf (const octave_int<T>& a, const float& b);
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
979
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
980 // Binary relations
4953
7a3a480e8645 [project @ 2004-09-01 21:10:28 by jwe]
jwe
parents: 4952
diff changeset
981
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
982 #define OCTAVE_INT_CMP_OP(OP, NAME) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
983 template <typename T1, typename T2> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
984 inline bool \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
985 operator OP (const octave_int<T1>& x, const octave_int<T2>& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
986 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
987 return octave_int_cmp_op::op<octave_int_cmp_op::NAME, T1, T2> (x.value (), y.value ()); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
988 }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
989
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
990 OCTAVE_INT_CMP_OP (<, lt)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
991 OCTAVE_INT_CMP_OP (<=, le)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
992 OCTAVE_INT_CMP_OP (>, gt)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
993 OCTAVE_INT_CMP_OP (>=, ge)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
994 OCTAVE_INT_CMP_OP (==, eq)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
995 OCTAVE_INT_CMP_OP (!=, ne)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
996
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
997 #undef OCTAVE_INT_CMP_OP
4953
7a3a480e8645 [project @ 2004-09-01 21:10:28 by jwe]
jwe
parents: 4952
diff changeset
998
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
999 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1000 inline std::ostream&
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1001 operator << (std::ostream& os, const octave_int<T>& ival)
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1002 {
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1003 os << ival.value ();
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1004 return os;
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1005 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1006
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
1007 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1008 inline std::istream&
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1009 operator >> (std::istream& is, octave_int<T>& ival)
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1010 {
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1011 T tmp = 0;
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1012 is >> tmp;
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1013 ival = tmp;
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1014 return is;
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1015 }
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1016
18252
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1017 // We need to specialise for char and unsigned char because
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1018 // std::operator<< and std::operator>> are overloaded to input and
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1019 // output the ASCII character values instead of a representation of
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
1020 // their numerical value (e.g., os << char(10) outputs a space instead
18252
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1021 // of outputting the characters '1' and '0')
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1022
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1023 template <>
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1024 inline std::ostream&
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1025 operator << (std::ostream& os, const octave_int<int8_t>& ival)
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1026 {
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1027 os << static_cast<int> (ival.value ());
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1028
18252
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1029 return os;
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1030 }
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1031
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1032 template <>
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1033 inline std::ostream&
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1034 operator << (std::ostream& os, const octave_int<uint8_t>& ival)
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1035 {
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1036 os << static_cast<unsigned int> (ival.value ());
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1037
18252
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1038 return os;
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1039 }
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1040
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1041 template <>
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1042 inline std::istream&
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1043 operator >> (std::istream& is, octave_int<int8_t>& ival)
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1044 {
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1045 int tmp = 0;
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1046 is >> tmp;
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1047 ival = static_cast<int8_t> (tmp);
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1048
18252
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1049 return is;
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1050 }
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1051
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1052 template <>
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1053 inline std::istream&
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1054 operator >> (std::istream& is, octave_int<uint8_t>& ival)
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1055 {
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1056 unsigned int tmp = 0;
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1057 is >> tmp;
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1058 ival = static_cast<uint8_t> (tmp);
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1059
18252
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1060 return is;
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1061 }
284e5c87f27b Fix saving int8 and uint8 in plain text format (bug #40980)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18017
diff changeset
1062
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1063 // Bitwise operations
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7598
diff changeset
1064
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1065 #define OCTAVE_INT_BITCMP_OP(OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1066 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1067 octave_int<T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1068 operator OP (const octave_int<T>& x, const octave_int<T>& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1069 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1070 return x.value () OP y.value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1071 }
4906
6754342ef7ad [project @ 2004-06-23 11:11:50 by jwe]
jwe
parents: 4902
diff changeset
1072
6754342ef7ad [project @ 2004-06-23 11:11:50 by jwe]
jwe
parents: 4902
diff changeset
1073 OCTAVE_INT_BITCMP_OP (&)
6754342ef7ad [project @ 2004-06-23 11:11:50 by jwe]
jwe
parents: 4902
diff changeset
1074 OCTAVE_INT_BITCMP_OP (|)
6754342ef7ad [project @ 2004-06-23 11:11:50 by jwe]
jwe
parents: 4902
diff changeset
1075 OCTAVE_INT_BITCMP_OP (^)
6754342ef7ad [project @ 2004-06-23 11:11:50 by jwe]
jwe
parents: 4902
diff changeset
1076
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1077 #undef OCTAVE_INT_BITCMP_OP
4906
6754342ef7ad [project @ 2004-06-23 11:11:50 by jwe]
jwe
parents: 4902
diff changeset
1078
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1079 // General bit shift.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
1080 template <typename T>
4909
5c9e36402f17 [project @ 2004-07-12 17:08:24 by jwe]
jwe
parents: 4906
diff changeset
1081 octave_int<T>
4920
b22a7a1db0d5 [project @ 2004-07-27 18:15:25 by jwe]
jwe
parents: 4919
diff changeset
1082 bitshift (const octave_int<T>& a, int n,
10312
cbc402e64d83 untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1083 const octave_int<T>& mask = std::numeric_limits<T>::max ())
4909
5c9e36402f17 [project @ 2004-07-12 17:08:24 by jwe]
jwe
parents: 4906
diff changeset
1084 {
5c9e36402f17 [project @ 2004-07-12 17:08:24 by jwe]
jwe
parents: 4906
diff changeset
1085 if (n > 0)
4952
bfd57b466752 [project @ 2004-09-01 00:49:05 by jwe]
jwe
parents: 4949
diff changeset
1086 return (a << n) & mask;
4909
5c9e36402f17 [project @ 2004-07-12 17:08:24 by jwe]
jwe
parents: 4906
diff changeset
1087 else if (n < 0)
4952
bfd57b466752 [project @ 2004-09-01 00:49:05 by jwe]
jwe
parents: 4949
diff changeset
1088 return (a >> -n) & mask;
4909
5c9e36402f17 [project @ 2004-07-12 17:08:24 by jwe]
jwe
parents: 4906
diff changeset
1089 else
8963
d1eab3ddb02d oct-inttypes.h (bitshift): apply mask even if not shifting
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
1090 return a & mask;
4909
5c9e36402f17 [project @ 2004-07-12 17:08:24 by jwe]
jwe
parents: 4906
diff changeset
1091 }
5c9e36402f17 [project @ 2004-07-12 17:08:24 by jwe]
jwe
parents: 4906
diff changeset
1092
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
1093 #if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
1094
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1095 # define OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_OP(T, OP) \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1096 extern OCTAVE_API T \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1097 external_double_ ## T ## _ ## OP (double x, T y); \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1098 \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1099 extern OCTAVE_API T \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
1100 external_ ## T ## _double_ ## OP (T x, double y)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
1101
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1102 # define OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_OPS(T) \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1103 OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_OP (T, add); \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1104 OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_OP (T, sub); \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1105 OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_OP (T, mul); \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1106 OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_OP (T, div)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
1107
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1108 OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_OPS (octave_int64);
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1109 OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_OPS (octave_uint64);
18005
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
1110
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
1111 #endif
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
1112
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1113 #define OCTAVE_INT_DOUBLE_BIN_OP0(OP) \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1114 template <typename T> \
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1115 inline octave_int<T> \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1116 operator OP (const octave_int<T>& x, const double& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1117 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1118 return octave_int<T> (static_cast<double> (x) OP y); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1119 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1120 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1121 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1122 inline octave_int<T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1123 operator OP (const double& x, const octave_int<T>& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1124 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1125 return octave_int<T> (x OP static_cast<double> (y)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1126 }
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1127
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21574
diff changeset
1128 #if defined (OCTAVE_INT_USE_LONG_DOUBLE)
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1129
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1130 // Handle mixed op using long double.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1131
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1132 # if defined (OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED)
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1133
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1134 # define OCTAVE_INT_DOUBLE_BIN_OP(OP, NAME) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1135 OCTAVE_INT_DOUBLE_BIN_OP0(OP) \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1136 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1137 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1138 inline octave_int64 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1139 operator OP (const double& x, const octave_int64& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1140 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1141 return external_double_octave_int64_ ## NAME (x, y); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1142 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1143 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1144 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1145 inline octave_uint64 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1146 operator OP (const double& x, const octave_uint64& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1147 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1148 return external_double_octave_uint64_ ## NAME (x, y); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1149 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1150 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1151 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1152 inline octave_int64 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1153 operator OP (const octave_int64& x, const double& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1154 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1155 return external_octave_int64_double_ ## NAME (x, y); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1156 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1157 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1158 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1159 inline octave_uint64 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1160 operator OP (const octave_uint64& x, const double& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1161 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1162 return external_octave_uint64_double_ ## NAME (x, y); \
17980
824c05a6d3ec avoid errors for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
1163 }
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1164
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1165 # else
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1166
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1167 # define OCTAVE_INT_DOUBLE_BIN_OP(OP, NAME) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1168 OCTAVE_INT_DOUBLE_BIN_OP0(OP) \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1169 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1170 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1171 inline octave_int64 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1172 operator OP (const double& x, const octave_int64& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1173 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1174 return octave_int64 (x OP static_cast<long double> (y.value ())); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1175 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1176 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1177 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1178 inline octave_uint64 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1179 operator OP (const double& x, const octave_uint64& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1180 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1181 return octave_uint64 (x OP static_cast<long double> (y.value ())); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1182 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1183 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1184 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1185 inline octave_int64 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1186 operator OP (const octave_int64& x, const double& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1187 { \
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
1188 return octave_int64 (static_cast<long double> (x.value ()) OP y); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1189 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1190 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1191 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1192 inline octave_uint64 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1193 operator OP (const octave_uint64& x, const double& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1194 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1195 return octave_uint64 (static_cast<long double> (x.value ()) OP y); \
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
1196 }
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1197
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1198 # endif
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1199
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1200 #else
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1201
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1202 // External handlers.
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1203
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1204 # define OCTAVE_INT_DOUBLE_BIN_OP(OP, NAME) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1205 OCTAVE_INT_DOUBLE_BIN_OP0(OP) \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1206 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1207 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1208 OCTAVE_API octave_int64 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1209 operator OP (const double&, const octave_int64&); \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1210 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1211 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1212 OCTAVE_API octave_uint64 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1213 operator OP (const double&, const octave_uint64&); \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1214 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1215 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1216 OCTAVE_API octave_int64 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1217 operator OP (const octave_int64&, const double&); \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1218 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1219 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1220 OCTAVE_API octave_uint64 \
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1221 operator OP (const octave_uint64&, const double&);
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents: 5030
diff changeset
1222
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1223 #endif
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents: 5030
diff changeset
1224
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
1225 OCTAVE_INT_DOUBLE_BIN_OP (+, add)
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
1226 OCTAVE_INT_DOUBLE_BIN_OP (-, sub)
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
1227 OCTAVE_INT_DOUBLE_BIN_OP (*, mul)
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17980
diff changeset
1228 OCTAVE_INT_DOUBLE_BIN_OP (/, div)
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents: 5030
diff changeset
1229
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1230 #undef OCTAVE_INT_DOUBLE_BIN_OP0
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1231 #undef OCTAVE_INT_DOUBLE_BIN_OP
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1232 #undef OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_OP
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1233 #undef OCTAVE_DECLARE_EXTERNAL_LONG_DOUBLE_INT_OPS
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents: 5030
diff changeset
1234
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1235 #define OCTAVE_INT_DOUBLE_CMP_OP(OP, NAME) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1236 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1237 inline bool \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1238 operator OP (const octave_int<T>& x, const double& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1239 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1240 return octave_int_cmp_op::mop<octave_int_cmp_op::NAME> (x.value (), y); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1241 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1242 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1243 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1244 inline bool \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1245 operator OP (const double& x, const octave_int<T>& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1246 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1247 return octave_int_cmp_op::mop<octave_int_cmp_op::NAME> (x, y.value ()); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1248 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents: 5030
diff changeset
1249
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1250 OCTAVE_INT_DOUBLE_CMP_OP (<, lt)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1251 OCTAVE_INT_DOUBLE_CMP_OP (<=, le)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1252 OCTAVE_INT_DOUBLE_CMP_OP (>=, ge)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1253 OCTAVE_INT_DOUBLE_CMP_OP (>, gt)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1254 OCTAVE_INT_DOUBLE_CMP_OP (==, eq)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1255 OCTAVE_INT_DOUBLE_CMP_OP (!=, ne)
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents: 5030
diff changeset
1256
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1257 #undef OCTAVE_INT_DOUBLE_CMP_OP
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1258
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1259 // Floats are handled by simply converting to doubles.
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents: 5030
diff changeset
1260
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1261 #define OCTAVE_INT_FLOAT_BIN_OP(OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1262 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1263 inline octave_int<T> \
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1264 operator OP (const octave_int<T>& x, float y) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1265 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1266 return x OP static_cast<double> (y); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1267 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1268 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1269 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1270 inline octave_int<T> \
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1271 operator OP (float x, const octave_int<T>& y) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1272 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1273 return static_cast<double> (x) OP y; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1274 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents: 5030
diff changeset
1275
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1276 OCTAVE_INT_FLOAT_BIN_OP (+)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1277 OCTAVE_INT_FLOAT_BIN_OP (-)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1278 OCTAVE_INT_FLOAT_BIN_OP (*)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1279 OCTAVE_INT_FLOAT_BIN_OP (/)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1280
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1281 #undef OCTAVE_INT_FLOAT_BIN_OP
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents: 5030
diff changeset
1282
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1283 #define OCTAVE_INT_FLOAT_CMP_OP(OP) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1284 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1285 inline bool \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1286 operator OP (const octave_int<T>& x, const float& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1287 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1288 return x OP static_cast<double> (y); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1289 } \
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1290 \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1291 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1292 bool \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1293 operator OP (const float& x, const octave_int<T>& y) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1294 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1295 return static_cast<double> (x) OP y; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22107
diff changeset
1296 }
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1297
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1298 OCTAVE_INT_FLOAT_CMP_OP (<)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1299 OCTAVE_INT_FLOAT_CMP_OP (<=)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1300 OCTAVE_INT_FLOAT_CMP_OP (>=)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1301 OCTAVE_INT_FLOAT_CMP_OP (>)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1302 OCTAVE_INT_FLOAT_CMP_OP (==)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1303 OCTAVE_INT_FLOAT_CMP_OP (!=)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8104
diff changeset
1304
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1305 #undef OCTAVE_INT_FLOAT_CMP_OP
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
1306
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
1307 template <typename T>
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9648
diff changeset
1308 octave_int<T>
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9648
diff changeset
1309 xmax (const octave_int<T>& x, const octave_int<T>& y)
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9648
diff changeset
1310 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
1311 const T xv = x.value ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
1312 const T yv = y.value ();
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1313
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1314 return octave_int<T> (xv >= yv ? xv : yv);
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9648
diff changeset
1315 }
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9648
diff changeset
1316
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
1317 template <typename T>
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9648
diff changeset
1318 octave_int<T>
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9648
diff changeset
1319 xmin (const octave_int<T>& x, const octave_int<T>& y)
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9648
diff changeset
1320 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
1321 const T xv = x.value ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
1322 const T yv = y.value ();
25847
c756e9a1e776 style fixes for oct-inttypes.h
John W. Eaton <jwe@octave.org>
parents: 25844
diff changeset
1323
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1324 return octave_int<T> (xv <= yv ? xv : yv);
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9648
diff changeset
1325 }
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9648
diff changeset
1326
28645
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1327 // Ints are handled by converting to octave_int type.
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1328
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1329 #define OCTAVE_INT_IDX_TYPE_BIN_OP(OP) \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1330 template <typename T> \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1331 inline octave_int<T> \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1332 operator OP (const octave_int<T>& x, octave_idx_type y) \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1333 { \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1334 return x OP octave_int<T> (y); \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1335 } \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1336 \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1337 template <typename T> \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1338 inline octave_int<T> \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1339 operator OP (octave_idx_type x, const octave_int<T>& y) \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1340 { \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1341 return octave_int<T> (x) OP y; \
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1342 }
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1343
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1344 OCTAVE_INT_IDX_TYPE_BIN_OP (+)
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1345 OCTAVE_INT_IDX_TYPE_BIN_OP (-)
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1346 OCTAVE_INT_IDX_TYPE_BIN_OP (*)
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1347 OCTAVE_INT_IDX_TYPE_BIN_OP (/)
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1348
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1349 #undef OCTAVE_INT_IDX_TYPE_BIN_OP
175eedccc085 define mixed-type operators for octave_idx_type and octave_int<T> values
John W. Eaton <jwe@octave.org>
parents: 27933
diff changeset
1350
4902
bd043a433918 [project @ 2004-06-14 18:46:20 by jwe]
jwe
parents:
diff changeset
1351 #endif