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