annotate liboctave/util/oct-inttypes.cc @ 21202:f7121e111991

maint: indent #ifdef blocks in liboctave and src directories. * Array-C.cc, Array-b.cc, Array-ch.cc, Array-d.cc, Array-f.cc, Array-fC.cc, Array-i.cc, Array-idx-vec.cc, Array-s.cc, Array-str.cc, Array-util.cc, Array-voidp.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc, CSparse.h, DiagArray2.cc, MArray-C.cc, MArray-d.cc, MArray-f.cc, MArray-fC.cc, MArray-i.cc, MArray-s.cc, MArray.cc, MDiagArray2.cc, MSparse-C.cc, MSparse-d.cc, MSparse.h, MatrixType.cc, PermMatrix.cc, Range.cc, Sparse-C.cc, Sparse-b.cc, Sparse-d.cc, Sparse.cc, boolMatrix.cc, boolNDArray.cc, boolSparse.cc, chMatrix.cc, chNDArray.cc, dColVector.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc, dSparse.h, dim-vector.cc, fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc, int16NDArray.cc, int32NDArray.cc, int64NDArray.cc, int8NDArray.cc, intNDArray.cc, uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc, uint8NDArray.cc, blaswrap.c, cquit.c, f77-extern.cc, f77-fcn.c, f77-fcn.h, lo-error.c, quit.cc, quit.h, CmplxAEPBAL.cc, CmplxCHOL.cc, CmplxGEPBAL.cc, CmplxHESS.cc, CmplxLU.cc, CmplxQR.cc, CmplxQRP.cc, CmplxSCHUR.cc, CmplxSVD.cc, CollocWt.cc, DASPK.cc, DASRT.cc, DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, base-lu.cc, base-qr.cc, dbleAEPBAL.cc, dbleCHOL.cc, dbleGEPBAL.cc, dbleHESS.cc, dbleLU.cc, dbleQR.cc, dbleQRP.cc, dbleSCHUR.cc, dbleSVD.cc, eigs-base.cc, fCmplxAEPBAL.cc, fCmplxCHOL.cc, fCmplxGEPBAL.cc, fCmplxHESS.cc, fCmplxLU.cc, fCmplxQR.cc, fCmplxQRP.cc, fCmplxSCHUR.cc, fCmplxSVD.cc, fEIG.cc, floatAEPBAL.cc, floatCHOL.cc, floatGEPBAL.cc, floatHESS.cc, floatLU.cc, floatQR.cc, floatQRP.cc, floatSCHUR.cc, floatSVD.cc, lo-mappers.cc, lo-specfun.cc, oct-convn.cc, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-rand.cc, oct-spparms.cc, randgamma.c, randmtzig.c, randpoisson.c, sparse-chol.cc, sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, mx-defs.h, dir-ops.cc, file-ops.cc, file-stat.cc, lo-sysdep.cc, mach-info.cc, oct-env.cc, oct-group.cc, oct-openmp.h, oct-passwd.cc, oct-syscalls.cc, oct-time.cc, oct-uname.cc, pathlen.h, sysdir.h, syswait.h, cmd-edit.cc, cmd-hist.cc, data-conv.cc, f2c-main.c, glob-match.cc, lo-array-errwarn.cc, lo-array-gripes.cc, lo-cutils.c, lo-cutils.h, lo-ieee.cc, lo-math.h, lo-regexp.cc, lo-utils.cc, oct-base64.cc, oct-glob.cc, oct-inttypes.cc, oct-inttypes.h, oct-locbuf.cc, oct-mutex.cc, oct-refcount.h, oct-rl-edit.c, oct-rl-hist.c, oct-shlib.cc, oct-sort.cc, pathsearch.cc, singleton-cleanup.cc, sparse-sort.cc, sparse-util.cc, statdefs.h, str-vec.cc, unwind-prot.cc, url-transfer.cc, display-available.h, main-cli.cc, main-gui.cc, main.in.cc, mkoctfile.in.cc, octave-config.in.cc, shared-fcns.h: indent #ifdef blocks in liboctave and src directories.
author Rik <rik@octave.org>
date Sat, 06 Feb 2016 06:40:13 -0800
parents 538b57866b90
children 40de9f8f23a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
1 /*
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18634
diff changeset
3 Copyright (C) 2004-2015 John W. Eaton
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4 Copyright (C) 2008-2009 Jaroslav Hajek
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
5
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
7
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
11 option) any later version.
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
12
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
16 for more details.
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
17
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
20 <http://www.gnu.org/licenses/>.
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
21
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
22 */
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
23
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21139
diff changeset
25 # include <config.h>
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
26 #endif
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
27
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
28 #include <fpucw.h>
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
29
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
30 #include "lo-error.h"
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
31
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
32 #include "oct-inttypes.h"
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
33
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
34 template <typename T>
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
35 const octave_int<T> octave_int<T>::zero (static_cast<T> (0));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
36
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
37 template <typename T>
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
38 const octave_int<T> octave_int<T>::one (static_cast<T> (1));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
39
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
40 // define type names.
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
41 #define DECLARE_OCTAVE_INT_TYPENAME(TYPE, TYPENAME) \
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
42 template <> \
8319
c374691576f6 Fix for MSVC compilation
Michael Goffioul <michael.goffioul@gmail.com>
parents: 8293
diff changeset
43 OCTAVE_API const char * \
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
44 octave_int<TYPE>::type_name () { return TYPENAME; }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
45
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
46 DECLARE_OCTAVE_INT_TYPENAME (int8_t, "int8")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
47 DECLARE_OCTAVE_INT_TYPENAME (int16_t, "int16")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
48 DECLARE_OCTAVE_INT_TYPENAME (int32_t, "int32")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
49 DECLARE_OCTAVE_INT_TYPENAME (int64_t, "int64")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
50 DECLARE_OCTAVE_INT_TYPENAME (uint8_t, "uint8")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
51 DECLARE_OCTAVE_INT_TYPENAME (uint16_t, "uint16")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
52 DECLARE_OCTAVE_INT_TYPENAME (uint32_t, "uint32")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
53 DECLARE_OCTAVE_INT_TYPENAME (uint64_t, "uint64")
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
54
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
55 #ifdef OCTAVE_INT_USE_LONG_DOUBLE
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
56
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
57 #ifdef OCTAVE_ENSURE_LONG_DOUBLE_OPERATIONS_ARE_NOT_TRUNCATED
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
58
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
59 #define DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES(T) \
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
60 template <typename xop> \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
61 bool \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
62 octave_int_cmp_op::external_mop (double x, T y) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
63 { \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
64 DECL_LONG_DOUBLE_ROUNDING \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
65 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
66 BEGIN_LONG_DOUBLE_ROUNDING (); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
67 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
68 bool retval = xop::op (static_cast<long double> (x), \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
69 static_cast<long double> (y)); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
70 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
71 END_LONG_DOUBLE_ROUNDING (); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
72 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
73 return retval; \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
74 } \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
75 \
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
76 template <typename xop> \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
77 bool \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
78 octave_int_cmp_op::external_mop (T x, double y) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
79 { \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
80 DECL_LONG_DOUBLE_ROUNDING \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
81 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
82 BEGIN_LONG_DOUBLE_ROUNDING (); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
83 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
84 bool retval = xop::op (static_cast<long double> (x), \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
85 static_cast<long double> (y)); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
86 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
87 END_LONG_DOUBLE_ROUNDING (); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
88 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
89 return retval; \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
90 }
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
91
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
92 DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES (int64_t)
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
93 DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES (uint64_t)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
94
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
95 #define INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP(OP, T) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
96 template OCTAVE_API bool \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
97 octave_int_cmp_op::external_mop<octave_int_cmp_op::OP> (double, T); \
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
98 template OCTAVE_API bool \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
99 octave_int_cmp_op::external_mop<octave_int_cmp_op::OP> (T, double)
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
100
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
101 #define INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS(T) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
102 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (lt, T); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
103 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (le, T); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
104 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (gt, T); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
105 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (ge, T); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
106 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (eq, T); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
107 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OP (ne, T)
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
108
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
109 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS (int64_t);
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
110 INSTANTIATE_LONG_DOUBLE_LONG_DOUBLE_CMP_OPS (uint64_t);
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
111
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
112 uint64_t
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
113 octave_external_uint64_uint64_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: 17843
diff changeset
114 {
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
115 DECL_LONG_DOUBLE_ROUNDING
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
116
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
117 BEGIN_LONG_DOUBLE_ROUNDING ();
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
118
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
119 uint64_t retval = octave_int_arith_base<uint64_t, false>::mul_internal (x, y);
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
120
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
121 END_LONG_DOUBLE_ROUNDING ();
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
122
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
123 return retval;
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
124 }
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
125
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
126 int64_t
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
127 octave_external_int64_int64_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: 17843
diff changeset
128 {
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
129 DECL_LONG_DOUBLE_ROUNDING
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
130
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
131 BEGIN_LONG_DOUBLE_ROUNDING ();
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
132
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
133 int64_t retval = octave_int_arith_base<int64_t, true>::mul_internal (x, y);
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
134
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
135 END_LONG_DOUBLE_ROUNDING ();
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
136
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
137 return retval;
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
138 }
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
139
18005
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
140 // Note that if we return long double it is apparently possible for
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
141 // truncation to happen at the point of storing the result in retval,
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
142 // which can happen after we end long double rounding. Attempt to avoid
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
143 // that problem by storing the full precision temporary value in the
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
144 // integer value before we end the long double rounding mode.
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
145 // Similarly, the conversion from the 64-bit integer type to long double
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
146 // must also occur in long double rounding mode.
18005
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
147
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
148 #define OCTAVE_LONG_DOUBLE_OP(T, OP, NAME) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
149 T \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
150 external_double_ ## T ## _ ## NAME (double x, T y) \
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
151 { \
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
152 DECL_LONG_DOUBLE_ROUNDING \
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
153 \
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
154 BEGIN_LONG_DOUBLE_ROUNDING (); \
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
155 \
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
156 T retval = T (x OP static_cast<long double> (y.value ())); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
157 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
158 END_LONG_DOUBLE_ROUNDING (); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
159 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
160 return retval; \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
161 } \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
162 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
163 T \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
164 external_ ## T ## _double_ ## NAME (T x, double y) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
165 { \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
166 DECL_LONG_DOUBLE_ROUNDING \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
167 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
168 BEGIN_LONG_DOUBLE_ROUNDING (); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
169 \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
170 T retval = T (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: 17843
diff changeset
171 \
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
172 END_LONG_DOUBLE_ROUNDING (); \
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
173 \
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
174 return retval; \
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
175 }
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
176
18017
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
177 #define OCTAVE_LONG_DOUBLE_OPS(T) \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
178 OCTAVE_LONG_DOUBLE_OP (T, +, add); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
179 OCTAVE_LONG_DOUBLE_OP (T, -, sub); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
180 OCTAVE_LONG_DOUBLE_OP (T, *, mul); \
0cd39f7f2409 additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 18005
diff changeset
181 OCTAVE_LONG_DOUBLE_OP (T, /, div)
18005
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
182
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
183 OCTAVE_LONG_DOUBLE_OPS(octave_int64);
79653c5b6147 make int64 ops implemented with long double work again (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17993
diff changeset
184 OCTAVE_LONG_DOUBLE_OPS(octave_uint64);
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
185
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
186 #endif
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
187
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
188 #else
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
189
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
190 // Define comparison operators
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
191
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
192 template <typename xop>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
193 bool
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8797
diff changeset
194 octave_int_cmp_op::emulate_mop (uint64_t x, double y)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
195 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
196 static const double xxup = std::numeric_limits<uint64_t>::max ();
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
197 // This converts to the nearest double. Unless there's an equality, the
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
198 // result is clear.
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
199 double xx = x;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
200 if (xx != y)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
201 return xop::op (xx, y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
202 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
203 {
21004
f7e416862e90 doc: fix spelling of "occurred".
Rafael Laboissiere <rafael@laboissiere.net>
parents: 19861
diff changeset
204 // If equality occurred we compare as integers.
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
205 if (xx == xxup)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
206 return xop::gtval;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
207 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
208 return xop::op (x, static_cast<uint64_t> (xx));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
209 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
210 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
211
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
212 template <typename xop>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
213 bool
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8797
diff changeset
214 octave_int_cmp_op::emulate_mop (int64_t x, double y)
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
215 {
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
216 static const double xxup = std::numeric_limits<int64_t>::max ();
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
217 static const double xxlo = std::numeric_limits<int64_t>::min ();
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
218 // This converts to the nearest double. Unless there's an equality, the
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
219 // result is clear.
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
220 double xx = x;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
221 if (xx != y)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
222 return xop::op (xx, y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
223 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
224 {
21004
f7e416862e90 doc: fix spelling of "occurred".
Rafael Laboissiere <rafael@laboissiere.net>
parents: 19861
diff changeset
225 // If equality occurred we compare as integers.
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
226 if (xx == xxup)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
227 return xop::gtval;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
228 else if (xx == xxlo)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
229 return xop::ltval;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
230 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
231 return xop::op (x, static_cast<int64_t> (xx));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
232 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
233
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
234 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
235
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
236 // We define double-int operations by reverting the operator
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
237
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
238 // A trait class reverting the operator
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
239 template <typename xop>
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
240 class rev_op
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
241 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
242 public:
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
243 typedef xop op;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
244 };
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
245
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
246 #define DEFINE_REVERTED_OPERATOR(OP1,OP2) \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
247 template <> \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
248 class rev_op<octave_int_cmp_op::OP1> \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
249 { \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
250 public: \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
251 typedef octave_int_cmp_op::OP2 op; \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
252 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
253
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
254 DEFINE_REVERTED_OPERATOR(lt,gt);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
255 DEFINE_REVERTED_OPERATOR(gt,lt);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
256 DEFINE_REVERTED_OPERATOR(le,ge);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
257 DEFINE_REVERTED_OPERATOR(ge,le);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
258
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
259 template <typename xop>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
260 bool
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8797
diff changeset
261 octave_int_cmp_op::emulate_mop (double x, uint64_t y)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
262 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
263 typedef typename rev_op<xop>::op rop;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
264 return mop<rop> (y, x);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
265 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
266
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
267 template <typename xop>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
268 bool
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8797
diff changeset
269 octave_int_cmp_op::emulate_mop (double x, int64_t y)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
270 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
271 typedef typename rev_op<xop>::op rop;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
272 return mop<rop> (y, x);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
273 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
274
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
275
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
276 // Define handlers for int64 multiplication
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
277
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
278 template <>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
279 uint64_t
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
280 octave_int_arith_base<uint64_t, false>::mul_internal (uint64_t x, uint64_t y)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
281 {
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
282 // Get upper words
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
283 uint64_t ux = x >> 32;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
284 uint64_t uy = y >> 32;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
285 uint64_t res;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
286 if (ux)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
287 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
288 if (uy)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
289 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
290 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
291 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
292 uint64_t ly = static_cast<uint32_t> (y);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
293 uint64_t uxly = ux*ly;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
294 if (uxly >> 32)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
295 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
296 uxly <<= 32; // never overflows
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
297 uint64_t lx = static_cast<uint32_t> (x);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
298 uint64_t lxly = lx*ly;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
299 res = add (uxly, lxly);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
300 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
301 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
302 else if (uy)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
303 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
304 uint64_t lx = static_cast<uint32_t> (x);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
305 uint64_t uylx = uy*lx;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
306 if (uylx >> 32)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
307 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
308 uylx <<= 32; // never overflows
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
309 uint64_t ly = static_cast<uint32_t> (y);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
310 uint64_t lylx = ly*lx;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
311 res = add (uylx, lylx);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
312 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
313 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
314 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
315 uint64_t lx = static_cast<uint32_t> (x);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
316 uint64_t ly = static_cast<uint32_t> (y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
317 res = lx*ly;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
318 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
319
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
320 return res;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
321
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
322 overflow:
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
323 return max_val ();
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
324 }
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
325
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
326 template <>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
327 int64_t
17993
ac9fd5010620 avoid including gnulib header in installed Octave header file (bug #40607)
John W. Eaton <jwe@octave.org>
parents: 17843
diff changeset
328 octave_int_arith_base<int64_t, true>::mul_internal (int64_t x, int64_t y)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
329 {
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
330 // The signed case is far worse. The problem is that
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
331 // even if neither integer fits into signed 32-bit range, the result may
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
332 // still be OK. Uh oh.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
333
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
334 // Essentially, what we do is compute sign, multiply absolute values
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
335 // (as above) and impose the sign.
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
336 // FIXME: can we do something faster if we HAVE_FAST_INT_OPS?
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
337
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
338 uint64_t usx = octave_int_abs (x);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
339 uint64_t usy = octave_int_abs (y);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
340 bool positive = (x < 0) == (y < 0);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
341
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
342 // Get upper words
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
343 uint64_t ux = usx >> 32;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
344 uint64_t uy = usy >> 32;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
345 uint64_t res;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
346 if (ux)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
347 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
348 if (uy)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
349 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
350 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
351 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
352 uint64_t ly = static_cast<uint32_t> (usy);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
353 uint64_t uxly = ux*ly;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
354 if (uxly >> 32)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
355 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
356 uxly <<= 32; // never overflows
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
357 uint64_t lx = static_cast<uint32_t> (usx);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
358 uint64_t lxly = lx*ly;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
359 res = uxly + lxly;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
360 if (res < uxly)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
361 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
362 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
363 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
364 else if (uy)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
365 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
366 uint64_t lx = static_cast<uint32_t> (usx);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
367 uint64_t uylx = uy*lx;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
368 if (uylx >> 32)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
369 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
370 uylx <<= 32; // never overflows
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
371 uint64_t ly = static_cast<uint32_t> (usy);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
372 uint64_t lylx = ly*lx;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
373 res = uylx + lylx;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
374 if (res < uylx)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
375 goto overflow;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
376 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
377 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
378 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
379 uint64_t lx = static_cast<uint32_t> (usx);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
380 uint64_t ly = static_cast<uint32_t> (usy);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
381 res = lx*ly;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
382 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
383
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
384 if (positive)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
385 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
386 if (res > static_cast<uint64_t> (max_val ()))
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
387 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
388 return max_val ();
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
389 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
390 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
391 return static_cast<int64_t> (res);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
392 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
393 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
394 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
395 if (res > static_cast<uint64_t> (-min_val ()))
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
396 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
397 return min_val ();
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
398 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
399 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
400 return -static_cast<int64_t> (res);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
401 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
402
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
403
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
404 overflow:
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
405 return positive ? max_val () : min_val ();
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
406
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
407 }
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
408
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
409 #define INT_DOUBLE_BINOP_DECL(OP,SUFFIX) \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
410 template <> \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
411 OCTAVE_API octave_ ## SUFFIX \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
412 operator OP (const octave_ ## SUFFIX & x, const double& y)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
413
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
414 #define DOUBLE_INT_BINOP_DECL(OP,SUFFIX) \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
415 template <> \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
416 OCTAVE_API octave_ ## SUFFIX \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
417 operator OP (const double& x, const octave_ ## SUFFIX & y)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
418
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
419 INT_DOUBLE_BINOP_DECL (+, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
420 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14427
diff changeset
421 return (y < 0) ? x - octave_uint64 (-y) : x + octave_uint64 (y);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
422 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
423
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
424 DOUBLE_INT_BINOP_DECL (+, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
425 { return y + x; }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
426
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
427 INT_DOUBLE_BINOP_DECL (+, int64)
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
428 {
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
429 if (fabs (y) < static_cast<double> (octave_int64::max ()))
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
430 return x + octave_int64 (y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
431 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
432 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
433 // If the number is within the int64 range (the most common case,
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
434 // probably), the above will work as expected. If not, it's more
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
435 // complicated - as long as y is within _twice_ the signed range, the
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
436 // result may still be an integer. An instance of such an operation is
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14427
diff changeset
437 // 3*2**62 + (1+intmin ('int64')) that should yield int64 (2**62) + 1. So
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
438 // what we do is to try to convert y/2 and add it twice. Note that if y/2
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
439 // overflows, the result must overflow as well, and that y/2 cannot be a
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
440 // fractional number.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
441 octave_int64 y2 (y / 2);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
442 return (x + y2) + y2;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
443 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
444 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
445
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
446 DOUBLE_INT_BINOP_DECL (+, int64)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
447 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
448 return y + x;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
449 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
450
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
451 INT_DOUBLE_BINOP_DECL (-, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
452 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
453 return x + (-y);
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
454 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
455
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
456 DOUBLE_INT_BINOP_DECL (-, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
457 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
458 if (x <= static_cast<double> (octave_uint64::max ()))
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14427
diff changeset
459 return octave_uint64 (x) - y;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
460 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
461 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
462 // Again a trick to get the corner cases right. Things like
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14427
diff changeset
463 // 3**2**63 - intmax ('uint64') should produce the correct result, i.e.
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14427
diff changeset
464 // int64 (2**63) + 1.
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
465 const double p2_64 = std::pow (2.0, 64);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
466 if (y.bool_value ())
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
467 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
468 const uint64_t p2_64my = (~y.value ()) + 1; // Equals 2**64 - y
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
469 return octave_uint64 (x - p2_64) + octave_uint64 (p2_64my);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
470 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
471 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
472 return octave_uint64 (p2_64);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
473 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
474 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
475
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
476 INT_DOUBLE_BINOP_DECL (-, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
477 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
478 return x + (-y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
479 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
480
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
481 DOUBLE_INT_BINOP_DECL (-, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
482 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
483 static const bool twosc = (std::numeric_limits<int64_t>::min ()
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
484 < -std::numeric_limits<int64_t>::max ());
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
485 // In case of symmetric integers (not two's complement), this will probably
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
486 // be eliminated at compile time.
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
487 if (twosc && y.value () == std::numeric_limits<int64_t>::min ())
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
488 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14427
diff changeset
489 return octave_int64 (x + std::pow (2.0, 63));
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
490 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
491 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
492 return x + (-y);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
493 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
494
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
495 // NOTE:
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
496 // Emulated mixed multiplications are tricky due to possible precision loss.
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
497 // Here, after sorting out common cases for speed, we follow the strategy
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
498 // of converting the double number into the form sign * 64-bit integer *
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
499 // 2**exponent, multiply the 64-bit integers to get a 128-bit number, split that
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
500 // number into 32-bit words and form 4 double-valued summands (none of which
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
501 // loses precision), then convert these into integers and sum them. Though it is
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
502 // not immediately obvious, this should work even w.r.t. rounding (none of the
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
503 // summands lose precision).
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
504
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
505 // Multiplies two unsigned 64-bit ints to get a 128-bit number represented
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
506 // as four 32-bit words.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
507 static void
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
508 umul128 (uint64_t x, uint64_t y, uint32_t w[4])
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
509 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
510 uint64_t lx = static_cast<uint32_t> (x);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
511 uint64_t ux = x >> 32;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
512 uint64_t ly = static_cast<uint32_t> (y);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
513 uint64_t uy = y >> 32;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
514 uint64_t a = lx * ly;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
515 w[0] = a; a >>= 32;
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
516 uint64_t uxly = ux*ly;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18017
diff changeset
517 uint64_t uylx = uy*lx;
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
518 a += static_cast<uint32_t> (uxly); uxly >>= 32;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
519 a += static_cast<uint32_t> (uylx); uylx >>= 32;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
520 w[1] = a; a >>= 32;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
521 uint64_t uxuy = ux * uy;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
522 a += uxly; a += uylx; a += uxuy;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
523 w[2] = a; a >>= 32;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
524 w[3] = a;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
525 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
526
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
527 // Splits a double into bool sign, unsigned 64-bit mantissa and int exponent
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
528 static void
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
529 dblesplit (double x, bool& sign, uint64_t& mtis, int& exp)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
530 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
531 sign = x < 0; x = fabs (x);
17843
573f865aa8c8 use gnulib frexp module
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
532 x = gnulib::frexp (x, &exp);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
533 exp -= 52;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
534 mtis = static_cast<uint64_t> (ldexp (x, 52));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
535 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
536
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
537 // Gets a double number from a
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
538 // 32-bit unsigned integer mantissa, exponent, and sign.
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
539 static double
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
540 dbleget (bool sign, uint32_t mtis, int exp)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
541 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
542 double x = ldexp (static_cast<double> (mtis), exp);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
543 return sign ? -x : x;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
544 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
545
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
546 INT_DOUBLE_BINOP_DECL (*, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
547 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
548 if (y >= 0 && y < octave_uint64::max () && y == xround (y))
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
549 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
550 return x * octave_uint64 (static_cast<uint64_t> (y));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
551 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
552 else if (y == 0.5)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
553 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
554 return x / octave_uint64 (static_cast<uint64_t> (2));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
555 }
9013
3b1908b58662 fixes in mixed int64-double multiply emulation
Jaroslav Hajek <highegg@gmail.com>
parents: 9003
diff changeset
556 else if (y < 0 || xisnan (y) || xisinf (y))
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
557 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
558 return octave_uint64 (x.value () * y);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
559 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
560 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
561 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
562 bool sign;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
563 uint64_t my;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
564 int e;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
565 dblesplit (y, sign, my, e);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
566 uint32_t w[4];
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
567 umul128 (x.value (), my, w);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
568 octave_uint64 res = octave_uint64::zero;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
569 for (short i = 0; i < 4; i++)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
570 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
571 res += octave_uint64 (dbleget (sign, w[i], e));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
572 e += 32;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
573 }
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
574 return res;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
575 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
576 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
577
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
578 DOUBLE_INT_BINOP_DECL (*, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
579 { return y * x; }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
580
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
581 INT_DOUBLE_BINOP_DECL (*, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
582 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
583 if (fabs (y) < octave_int64::max () && y == xround (y))
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
584 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
585 return x * octave_int64 (static_cast<int64_t> (y));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
586 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
587 else if (fabs (y) == 0.5)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
588 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
589 return x / octave_int64 (static_cast<uint64_t> (4*y));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
590 }
9013
3b1908b58662 fixes in mixed int64-double multiply emulation
Jaroslav Hajek <highegg@gmail.com>
parents: 9003
diff changeset
591 else if (xisnan (y) || xisinf (y))
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
592 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
593 return octave_int64 (x.value () * y);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
594 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
595 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
596 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
597 bool sign;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
598 uint64_t my;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
599 int e;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
600 dblesplit (y, sign, my, e);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
601 uint32_t w[4];
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
602 sign = (sign != (x.value () < 0));
8293
ad5bb02d267a workaround missing std::abs(int64_t) in MSVC
Jaroslav Hajek <highegg@gmail.com>
parents: 8202
diff changeset
603 umul128 (octave_int_abs (x.value ()), my, w);
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
604 octave_int64 res = octave_int64::zero;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
605 for (short i = 0; i < 4; i++)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
606 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
607 res += octave_int64 (dbleget (sign, w[i], e));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
608 e += 32;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
609 }
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
610 return res;
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
611 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
612 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
613
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
614 DOUBLE_INT_BINOP_DECL (*, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
615 { return y * x; }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
616
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
617 DOUBLE_INT_BINOP_DECL (/, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
618 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
619 return octave_uint64 (x / static_cast<double> (y));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
620 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
621
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
622 DOUBLE_INT_BINOP_DECL (/, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
623 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
624 return octave_int64 (x / static_cast<double> (y));
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
625 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
626
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
627 INT_DOUBLE_BINOP_DECL (/, uint64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
628 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
629 if (y >= 0 && y < octave_uint64::max () && y == xround (y))
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
630 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
631 return x / octave_uint64 (y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
632 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
633 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
634 return x * (1.0/y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
635 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
636
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
637 INT_DOUBLE_BINOP_DECL (/, int64)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
638 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
639 if (fabs (y) < octave_int64::max () && y == xround (y))
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
640 {
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
641 return x / octave_int64 (y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
642 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
643 else
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
644 return x * (1.0/y);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
645 }
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
646
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
647 #define INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP,T1,T2) \
9237
3c1762c7e787 Add missing xxx_API decoration and remove misplaced ones
Michael Goffioul <michael.goffioul@gmail.com>
parents: 9013
diff changeset
648 template OCTAVE_API bool \
8856
ab4db66e286f workaround gcc 4.3 explicit instantiation bug in octave_int_cmp_op
Jaroslav Hajek <highegg@gmail.com>
parents: 8797
diff changeset
649 octave_int_cmp_op::emulate_mop<octave_int_cmp_op::OP> (T1 x, T2 y)
8185
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
650
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
651 #define INSTANTIATE_INT64_DOUBLE_CMP_OP(OP) \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
652 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, int64_t); \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
653 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, double, uint64_t); \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
654 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, int64_t, double); \
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
655 INSTANTIATE_INT64_DOUBLE_CMP_OP0(OP, uint64_t, double)
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
656
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
657 INSTANTIATE_INT64_DOUBLE_CMP_OP(lt);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
658 INSTANTIATE_INT64_DOUBLE_CMP_OP(le);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
659 INSTANTIATE_INT64_DOUBLE_CMP_OP(gt);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
660 INSTANTIATE_INT64_DOUBLE_CMP_OP(ge);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
661 INSTANTIATE_INT64_DOUBLE_CMP_OP(eq);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
662 INSTANTIATE_INT64_DOUBLE_CMP_OP(ne);
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
663
69c5cce38c29 implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8169
diff changeset
664 #endif
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
665
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
666 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
667 octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
668 pow (const octave_int<T>& a, const octave_int<T>& b)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
669 {
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
670 octave_int<T> retval;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
671
8864
4d328b8979c8 simplify integer power
Jaroslav Hajek <highegg@gmail.com>
parents: 8856
diff changeset
672 octave_int<T> zero = static_cast<T> (0);
4d328b8979c8 simplify integer power
Jaroslav Hajek <highegg@gmail.com>
parents: 8856
diff changeset
673 octave_int<T> one = static_cast<T> (1);
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
674
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
675 if (b == zero || a == one)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
676 retval = one;
8864
4d328b8979c8 simplify integer power
Jaroslav Hajek <highegg@gmail.com>
parents: 8856
diff changeset
677 else if (b < zero)
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
678 {
8864
4d328b8979c8 simplify integer power
Jaroslav Hajek <highegg@gmail.com>
parents: 8856
diff changeset
679 if (a == -one)
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
680 retval = (b.value () % 2) ? a : one;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
681 else
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
682 retval = zero;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
683 }
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
684 else
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
685 {
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
686 octave_int<T> a_val = a;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
687 T b_val = b; // no need to do saturation on b
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
688
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
689 retval = a;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
690
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
691 b_val -= 1;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
692
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
693 while (b_val != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
694 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
695 if (b_val & 1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
696 retval = retval * a_val;
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
697
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
698 b_val = b_val >> 1;
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
699
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
700 if (b_val)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
701 a_val = a_val * a_val;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
702 }
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
703 }
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
704
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
705 return retval;
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
706 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
707
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
708 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
709 octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
710 pow (const double& a, const octave_int<T>& b)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
711 { return octave_int<T> (pow (a, b.double_value ())); }
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
712
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
713 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
714 octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
715 pow (const octave_int<T>& a, const double& b)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
716 {
8195
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
717 return ((b >= 0 && b < std::numeric_limits<T>::digits && b == xround (b))
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
718 ? pow (a, octave_int<T> (static_cast<T> (b)))
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
719 : octave_int<T> (pow (a.double_value (), b)));
8195
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
720 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
721
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
722 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
723 octave_int<T>
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
724 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
725 { return octave_int<T> (pow (a, b.float_value ())); }
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
726
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
727 template <typename T>
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
728 octave_int<T>
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
729 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
730 {
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
731 return ((b >= 0 && b < std::numeric_limits<T>::digits && b == xround (b))
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
732 ? pow (a, octave_int<T> (static_cast<T> (b)))
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
733 : octave_int<T> (pow (a.double_value (), static_cast<double> (b))));
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
734 }
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
735
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
736 // 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
737 // 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
738 // one?
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
739 template <typename T>
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
740 octave_int<T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
741 powf (const float& a, const octave_int<T>& b)
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
742 { return octave_int<T> (pow (a, b.float_value ())); }
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
743
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21004
diff changeset
744 template <typename T>
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
745 octave_int<T>
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
746 powf (const octave_int<T>& a, const float& b)
8195
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
747 {
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
748 return ((b >= 0 && b < std::numeric_limits<T>::digits && b == xround (b))
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
749 ? pow (a, octave_int<T> (static_cast<T> (b)))
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
750 : octave_int<T> (pow (a.double_value (), static_cast<double> (b))));
8195
ec3a55bd876b fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents: 8192
diff changeset
751 }
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
752
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
753 #define INSTANTIATE_INTTYPE(T) \
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 6105
diff changeset
754 template class OCTAVE_API octave_int<T>; \
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 6105
diff changeset
755 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const octave_int<T>&); \
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
756 template OCTAVE_API octave_int<T> pow (const double&, const octave_int<T>&); \
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
757 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const double&); \
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
758 template OCTAVE_API octave_int<T> pow (const float&, const octave_int<T>&); \
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
759 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const float&); \
8169
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
760 template OCTAVE_API octave_int<T> powf (const float&, const octave_int<T>&); \
66bc6f9b4f72 rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 7521
diff changeset
761 template OCTAVE_API octave_int<T> powf (const octave_int<T>&, const float&); \
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 6105
diff changeset
762 template OCTAVE_API octave_int<T> \
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
763 bitshift (const octave_int<T>&, int, const octave_int<T>&);
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
764
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
765 INSTANTIATE_INTTYPE (int8_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
766 INSTANTIATE_INTTYPE (int16_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
767 INSTANTIATE_INTTYPE (int32_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
768 INSTANTIATE_INTTYPE (int64_t);
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
769
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
770 INSTANTIATE_INTTYPE (uint8_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
771 INSTANTIATE_INTTYPE (uint16_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
772 INSTANTIATE_INTTYPE (uint32_t);
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5307
diff changeset
773 INSTANTIATE_INTTYPE (uint64_t);
5072
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
774
97b62f0c1bee [project @ 2004-11-09 05:51:30 by jwe]
jwe
parents:
diff changeset
775
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
776 /*
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
777
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
778 %!assert (intmax ("int64") / intmin ("int64"), int64 (-1))
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
779 %!assert (intmin ("int64") / int64 (-1), intmax ("int64"))
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
780 %!assert (int64 (2**63), intmax ("int64"))
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
781 %!assert (uint64 (2**64), intmax ("uint64"))
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
782 %!test
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
783 %! a = 1.9*2^61; b = uint64 (a); b++; assert (b > a);
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
784 %!test
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
785 %! a = -1.9*2^61; b = int64 (a); b++; assert (b > a);
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
786 %!test
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
787 %! a = int64 (-2**60) + 2; assert (1.25*a == (5*a)/4);
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
788 %!test
14427
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
789 %! a = uint64 (2**61) + 2; assert (1.25*a == (5*a)/4);
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
790 %!assert (int32 (2**31+0.5), intmax ("int32"))
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
791 %!assert (int32 (-2**31-0.5), intmin ("int32"))
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
792 %!assert ((int64 (2**62)+1)**1, int64 (2**62)+1)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
793 %!assert ((int64 (2**30)+1)**2, int64 (2**60+2**31) + 1)
d07e989686b0 Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
794
18628
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
795 %!assert (uint8 (char (128)), uint8 (128));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
796 %!assert (uint8 (char (255)), uint8 (255));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
797 %!assert (int8 (char (128)), int8 (128));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
798 %!assert (int8 (char (255)), int8 (255));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
799
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
800 %!assert (uint16 (char (128)), uint16 (128));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
801 %!assert (uint16 (char (255)), uint16 (255));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
802 %!assert (int16 (char (128)), int16 (128));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
803 %!assert (int16 (char (255)), int16 (255));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
804
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
805 %!assert (uint32 (char (128)), uint32 (128));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
806 %!assert (uint32 (char (255)), uint32 (255));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
807 %!assert (int32 (char (128)), int32 (128));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
808 %!assert (int32 (char (255)), int32 (255));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
809
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
810 %!assert (uint64 (char (128)), uint64 (128));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
811 %!assert (uint64 (char (255)), uint64 (255));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
812 %!assert (int64 (char (128)), int64 (128));
c644ed73c6ce tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents: 18017
diff changeset
813 %!assert (int64 (char (255)), int64 (255));
8192
9a0a66f650b1 tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents: 8185
diff changeset
814 */