Mercurial > hg > octave-nkf
annotate liboctave/util/oct-inttypes.cc @ 20330:2db2db2df55b
Automatically convert arrays of java primitives into Octave types (bug #44882)
* libinterp/octave-value/ov-java.cc (box): when the result of a java method is
a java primitive type, these are converted to octave types automatically. We
seem to be handling this correctly for scalars but not for arrays yet. This
fixes it on the java -> octave direction.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Mon, 20 Apr 2015 15:01:27 +0100 |
parents | 19755f4fc851 |
children |
rev | line source |
---|---|
5072 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18782
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 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5072 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5072 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
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 | 32 #include "oct-inttypes.h" |
33 | |
8185
69c5cce38c29
implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents:
8169
diff
changeset
|
34 template<class T> |
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 |
69c5cce38c29
implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents:
8169
diff
changeset
|
37 template<class T> |
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 | 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) \ |
0cd39f7f2409
additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents:
18005
diff
changeset
|
60 template <class xop> \ |
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 \ |
0cd39f7f2409
additional improvements for int64 ops implemented with long double (bug #40607)
John W. Eaton <jwe@octave.org>
parents:
18005
diff
changeset
|
76 template <class xop> \ |
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 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
192 template <class xop> |
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 { |
69c5cce38c29
implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents:
8169
diff
changeset
|
204 // If equality occured we compare as integers. |
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 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
212 template <class xop> |
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 { |
69c5cce38c29
implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents:
8169
diff
changeset
|
225 // If equality occured we compare as integers. |
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 | 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 |
69c5cce38c29
implement 64-bit arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents:
8169
diff
changeset
|
239 template <class xop> |
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 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
259 template <class xop> |
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 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
267 template <class xop> |
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 | 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 | 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 | 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 | 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 |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
666 //template <class T> |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
667 //bool |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
668 //xisnan (const octave_int<T>&) |
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 // return false; |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
671 //} |
5072 | 672 |
8169
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
673 template <class T> |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
674 octave_int<T> |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
675 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
|
676 { |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
677 octave_int<T> retval; |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
678 |
8864 | 679 octave_int<T> zero = static_cast<T> (0); |
680 octave_int<T> one = static_cast<T> (1); | |
8169
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
681 |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
682 if (b == zero || a == one) |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
683 retval = one; |
8864 | 684 else if (b < zero) |
8169
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
685 { |
8864 | 686 if (a == -one) |
8169
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
687 retval = (b.value () % 2) ? a : one; |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
688 else |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
689 retval = zero; |
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 else |
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 octave_int<T> a_val = a; |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
694 T b_val = b; // no need to do saturation on b |
5072 | 695 |
8169
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
696 retval = a; |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
697 |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
698 b_val -= 1; |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
699 |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
700 while (b_val != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
701 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
702 if (b_val & 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
703 retval = retval * a_val; |
8169
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
704 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
705 b_val = b_val >> 1; |
8169
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
706 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
707 if (b_val) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
708 a_val = a_val * a_val; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
709 } |
8169
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
710 } |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
711 |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
712 return retval; |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
713 } |
5072 | 714 |
8169
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
715 template <class T> |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
716 octave_int<T> |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
717 pow (const double& a, const octave_int<T>& b) |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
718 { return octave_int<T> (pow (a, b.double_value ())); } |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
719 |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
720 template <class T> |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
721 octave_int<T> |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
722 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
|
723 { |
8195
ec3a55bd876b
fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents:
8192
diff
changeset
|
724 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
|
725 ? 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
|
726 : octave_int<T> (pow (a.double_value (), b))); |
8195
ec3a55bd876b
fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents:
8192
diff
changeset
|
727 } |
5072 | 728 |
8169
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
729 template <class T> |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
730 octave_int<T> |
13012
15eefbd9d4e8
Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
731 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
|
732 { 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
|
733 |
15eefbd9d4e8
Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
734 template <class T> |
15eefbd9d4e8
Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
735 octave_int<T> |
15eefbd9d4e8
Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
736 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
|
737 { |
15eefbd9d4e8
Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
738 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
|
739 ? 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
|
740 : 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
|
741 } |
15eefbd9d4e8
Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
742 |
15eefbd9d4e8
Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
743 // 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
|
744 // 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
|
745 // one? |
15eefbd9d4e8
Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
746 template <class T> |
15eefbd9d4e8
Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
747 octave_int<T> |
8169
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
748 powf (const float& a, const octave_int<T>& b) |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
749 { return octave_int<T> (pow (a, b.float_value ())); } |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
750 |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
751 template <class T> |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
752 octave_int<T> |
66bc6f9b4f72
rewrite integer arithmetics and conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
7521
diff
changeset
|
753 powf (const octave_int<T>& a, const float& b) |
8195
ec3a55bd876b
fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents:
8192
diff
changeset
|
754 { |
ec3a55bd876b
fix integer exponentiation
Jaroslav Hajek <highegg@gmail.com>
parents:
8192
diff
changeset
|
755 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
|
756 ? 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
|
757 : 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
|
758 } |
5072 | 759 |
760 #define INSTANTIATE_INTTYPE(T) \ | |
6108 | 761 template class OCTAVE_API octave_int<T>; \ |
762 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
|
763 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
|
764 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
|
765 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
|
766 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
|
767 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
|
768 template OCTAVE_API octave_int<T> powf (const octave_int<T>&, const float&); \ |
6108 | 769 template OCTAVE_API octave_int<T> \ |
20068
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
770 bitshift (const octave_int<T>&, int, const octave_int<T>&); |
5072 | 771 |
5828 | 772 INSTANTIATE_INTTYPE (int8_t); |
773 INSTANTIATE_INTTYPE (int16_t); | |
774 INSTANTIATE_INTTYPE (int32_t); | |
775 INSTANTIATE_INTTYPE (int64_t); | |
5072 | 776 |
5828 | 777 INSTANTIATE_INTTYPE (uint8_t); |
778 INSTANTIATE_INTTYPE (uint16_t); | |
779 INSTANTIATE_INTTYPE (uint32_t); | |
780 INSTANTIATE_INTTYPE (uint64_t); | |
5072 | 781 |
782 | |
8192
9a0a66f650b1
tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents:
8185
diff
changeset
|
783 /* |
9a0a66f650b1
tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents:
8185
diff
changeset
|
784 |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
785 %!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
|
786 %!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
|
787 %!assert (int64 (2**63), intmax ("int64")) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
788 %!assert (uint64 (2**64), intmax ("uint64")) |
8192
9a0a66f650b1
tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents:
8185
diff
changeset
|
789 %!test |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
790 %! 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
|
791 %!test |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
792 %! 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
|
793 %!test |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
794 %! 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
|
795 %!test |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
796 %! 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
|
797 %!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
|
798 %!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
|
799 %!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
|
800 %!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
|
801 |
18776
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
802 %!assert (uint8 (char (128)), uint8 (128)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
803 %!assert (uint8 (char (255)), uint8 (255)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
804 %!assert (int8 (char (128)), int8 (128)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
805 %!assert (int8 (char (255)), int8 (255)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
806 |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
807 %!assert (uint16 (char (128)), uint16 (128)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
808 %!assert (uint16 (char (255)), uint16 (255)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
809 %!assert (int16 (char (128)), int16 (128)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
810 %!assert (int16 (char (255)), int16 (255)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
811 |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
812 %!assert (uint32 (char (128)), uint32 (128)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
813 %!assert (uint32 (char (255)), uint32 (255)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
814 %!assert (int32 (char (128)), int32 (128)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
815 %!assert (int32 (char (255)), int32 (255)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
816 |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
817 %!assert (uint64 (char (128)), uint64 (128)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
818 %!assert (uint64 (char (255)), uint64 (255)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
819 %!assert (int64 (char (128)), int64 (128)); |
c644ed73c6ce
tests missing from previous commit
John W. Eaton <jwe@octave.org>
parents:
18017
diff
changeset
|
820 %!assert (int64 (char (255)), int64 (255)); |
8192
9a0a66f650b1
tests for int64 arithmetics
Jaroslav Hajek <highegg@gmail.com>
parents:
8185
diff
changeset
|
821 */ |