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