annotate libinterp/operators/op-mi.cc @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents b260322f6730
children e88a07dec498
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28588
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 ////////////////////////////////////////////////////////////////////////
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29989
diff changeset
3 // Copyright (C) 2020-2022 The Octave Project Developers
28588
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 //
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 // distribution or <https://octave.org/copyright/>.
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 //
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 // This file is part of Octave.
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 //
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 // under the terms of the GNU General Public License as published by
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 // (at your option) any later version.
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 //
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 // GNU General Public License for more details.
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 //
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 // along with Octave; see the file COPYING. If not, see
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 // <https://www.gnu.org/licenses/>.
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 //
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 ////////////////////////////////////////////////////////////////////////
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if defined (HAVE_CONFIG_H)
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 # include "config.h"
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include <iostream>
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include "errwarn.h"
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include "ops.h"
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "ov-magic-int.h"
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "ov-typeinfo.h"
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include "ov.h"
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
29989
b260322f6730 move xdiv, xnorm, and xpow inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29882
diff changeset
38 OCTAVE_NAMESPACE_BEGIN
b260322f6730 move xdiv, xnorm, and xpow inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29882
diff changeset
39
28588
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 // Magic integer unary ops. Only + and - are allowed so that
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 // expressions like
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 //
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 // int64 (-9007199254740994)
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 //
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 // produce proper int64 constants.
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 static octave_value
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 oct_unop_unsigned_uplus (const octave_base_value& a)
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 {
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 const octave_magic_uint& v = dynamic_cast<const octave_magic_uint&> (a);
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 // no-op.
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 // FIXME: but can we do this just by incrementing the reference count?
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 return octave_value (v.clone ());
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 }
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 static octave_value
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 oct_unop_unsigned_uminus (const octave_base_value& a)
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 {
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 const octave_magic_uint& v = dynamic_cast<const octave_magic_uint&> (a);
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 // We are storing a uint64 value, so some fakery is needed here.
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 // Is there a better way?
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63
29882
38c47f8f7cd6 allow int64 (-large_int) to work properly again (bug #45945)
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
64 // FIXME: Maybe there should also be octave_magic_int::as_TYPE_value
38c47f8f7cd6 allow int64 (-large_int) to work properly again (bug #45945)
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
65 // functions?
38c47f8f7cd6 allow int64 (-large_int) to work properly again (bug #45945)
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
66 octave_uint64 val (v.scalar_ref ());
28588
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 uint64_t ival = val.value ();
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 static const uint64_t max_val
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 = static_cast<uint64_t> (std::numeric_limits<int64_t>::max ());
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 static const uint64_t max_val_p1 = max_val + 1;
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 if (ival <= max_val)
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 {
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 int64_t signed_ival = ival;
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 return octave_value (new octave_magic_int (-signed_ival));
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 }
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 if (ival == max_val_p1)
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 {
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 // Correctly capture intmin. For example, negating uint8(128)
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 // should return int8(-128) but converting directly to int8 and
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 // negating will not return the correct result.
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 static const int64_t min_signed_ival
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 = std::numeric_limits<int64_t>::min ();
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 return octave_value (new octave_magic_int (min_signed_ival));
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 }
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 return octave_value (-static_cast<double> (ival));
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 }
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 static octave_value
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 oct_unop_signed_uplus (const octave_base_value& a)
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 {
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 const octave_magic_int& v = dynamic_cast<const octave_magic_int&> (a);
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 // no-op.
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 // FIXME: but can we do this just by incrementing the reference count?
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 return octave_value (v.clone ());
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 }
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 static octave_value
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 oct_unop_signed_uminus (const octave_base_value& a)
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 {
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 const octave_magic_int& v = dynamic_cast<const octave_magic_int&> (a);
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109
29882
38c47f8f7cd6 allow int64 (-large_int) to work properly again (bug #45945)
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
110 // FIXME: Maybe there should also be octave_magic_int::as_TYPE_value
38c47f8f7cd6 allow int64 (-large_int) to work properly again (bug #45945)
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
111 // functions?
38c47f8f7cd6 allow int64 (-large_int) to work properly again (bug #45945)
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
112 octave_int64 val (v.scalar_ref ());
28588
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 return octave_value (new octave_magic_int (-val));
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 }
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 void
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 install_mi_ops (octave::type_info& ti)
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 {
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 INSTALL_UNOP_TI (ti, op_uplus, octave_magic_uint, unsigned_uplus);
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 INSTALL_UNOP_TI (ti, op_uminus, octave_magic_uint, unsigned_uminus);
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 INSTALL_UNOP_TI (ti, op_uplus, octave_magic_int, signed_uplus);
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 INSTALL_UNOP_TI (ti, op_uminus, octave_magic_int, signed_uminus);
ee9b1081471f allow integer constants > flintmax to be represented exactly (bug #45945)
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 }
29989
b260322f6730 move xdiv, xnorm, and xpow inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29882
diff changeset
126
b260322f6730 move xdiv, xnorm, and xpow inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29882
diff changeset
127 OCTAVE_NAMESPACE_END