2928
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
2928
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
2928
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "gripes.h" |
4055
|
28 #include "oct-obj.h" |
2928
|
29 #include "ov.h" |
|
30 #include "ov-complex.h" |
|
31 #include "ov-cx-mat.h" |
|
32 #include "ov-typeinfo.h" |
|
33 #include "ops.h" |
|
34 #include "xdiv.h" |
|
35 #include "xpow.h" |
|
36 |
3203
|
37 // unary complex scalar ops. |
|
38 |
|
39 DEFUNOP (not, complex) |
|
40 { |
|
41 CAST_UNOP_ARG (const octave_complex&); |
|
42 |
|
43 return octave_value (v.complex_value () == 0.0); |
|
44 } |
|
45 |
4965
|
46 DEFUNOP_OP (uplus, complex, /* no-op */) |
3203
|
47 DEFUNOP_OP (uminus, complex, -) |
|
48 DEFUNOP_OP (transpose, complex, /* no-op */) |
|
49 |
|
50 DEFUNOP (hermitian, complex) |
|
51 { |
|
52 CAST_UNOP_ARG (const octave_complex&); |
|
53 |
|
54 return octave_value (conj (v.complex_value ())); |
|
55 } |
|
56 |
|
57 DEFNCUNOP_METHOD (incr, complex, increment) |
|
58 DEFNCUNOP_METHOD (decr, complex, decrement) |
|
59 |
2928
|
60 // complex scalar by complex scalar ops. |
|
61 |
|
62 DEFBINOP_OP (add, complex, complex, +) |
|
63 DEFBINOP_OP (sub, complex, complex, -) |
|
64 DEFBINOP_OP (mul, complex, complex, *) |
|
65 |
|
66 DEFBINOP (div, complex, complex) |
|
67 { |
|
68 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
69 |
|
70 Complex d = v2.complex_value (); |
|
71 |
|
72 if (d == 0.0) |
|
73 gripe_divide_by_zero (); |
|
74 |
|
75 return octave_value (v1.complex_value () / d); |
|
76 } |
|
77 |
|
78 DEFBINOP_FN (pow, complex, complex, xpow) |
|
79 |
|
80 DEFBINOP (ldiv, complex, complex) |
|
81 { |
|
82 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
83 |
|
84 Complex d = v1.complex_value (); |
|
85 |
|
86 if (d == 0.0) |
|
87 gripe_divide_by_zero (); |
|
88 |
|
89 return octave_value (v2.complex_value () / d); |
|
90 } |
|
91 |
|
92 DEFBINOP (lt, complex, complex) |
|
93 { |
|
94 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
95 |
|
96 return real (v1.complex_value ()) < real (v2.complex_value ()); |
|
97 } |
|
98 |
|
99 DEFBINOP (le, complex, complex) |
|
100 { |
|
101 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
102 |
|
103 return real (v1.complex_value ()) <= real (v2.complex_value ()); |
|
104 } |
|
105 |
|
106 DEFBINOP (eq, complex, complex) |
|
107 { |
|
108 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
109 |
|
110 return v1.complex_value () == v2.complex_value (); |
|
111 } |
|
112 |
|
113 DEFBINOP (ge, complex, complex) |
|
114 { |
|
115 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
116 |
|
117 return real (v1.complex_value ()) >= real (v2.complex_value ()); |
|
118 } |
|
119 |
|
120 DEFBINOP (gt, complex, complex) |
|
121 { |
|
122 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
123 |
|
124 return real (v1.complex_value ()) > real (v2.complex_value ()); |
|
125 } |
|
126 |
|
127 DEFBINOP (ne, complex, complex) |
|
128 { |
|
129 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
130 |
|
131 return v1.complex_value () != v2.complex_value (); |
|
132 } |
|
133 |
|
134 DEFBINOP_OP (el_mul, complex, complex, *) |
|
135 |
|
136 DEFBINOP (el_div, complex, complex) |
|
137 { |
|
138 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
139 |
|
140 Complex d = v2.complex_value (); |
|
141 |
|
142 if (d == 0.0) |
|
143 gripe_divide_by_zero (); |
|
144 |
|
145 return octave_value (v1.complex_value () / d); |
|
146 } |
|
147 |
|
148 DEFBINOP_FN (el_pow, complex, complex, xpow) |
|
149 |
|
150 DEFBINOP (el_ldiv, complex, complex) |
|
151 { |
|
152 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
153 |
|
154 Complex d = v1.complex_value (); |
|
155 |
|
156 if (d == 0.0) |
|
157 gripe_divide_by_zero (); |
|
158 |
|
159 return octave_value (v2.complex_value () / d); |
|
160 } |
|
161 |
|
162 DEFBINOP (el_and, complex, complex) |
|
163 { |
|
164 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
165 |
|
166 return v1.complex_value () != 0.0 && v2.complex_value () != 0.0; |
|
167 } |
|
168 |
|
169 DEFBINOP (el_or, complex, complex) |
|
170 { |
|
171 CAST_BINOP_ARGS (const octave_complex&, const octave_complex&); |
|
172 |
|
173 return v1.complex_value () != 0.0 || v2.complex_value () != 0.0; |
|
174 } |
|
175 |
4915
|
176 DEFNDCATOP_FN (cs_cs, complex, complex, complex_array, complex_array, concat) |
|
177 |
2928
|
178 void |
|
179 install_cs_cs_ops (void) |
|
180 { |
3538
|
181 INSTALL_UNOP (op_not, octave_complex, not); |
4965
|
182 INSTALL_UNOP (op_uplus, octave_complex, uplus); |
3538
|
183 INSTALL_UNOP (op_uminus, octave_complex, uminus); |
|
184 INSTALL_UNOP (op_transpose, octave_complex, transpose); |
|
185 INSTALL_UNOP (op_hermitian, octave_complex, hermitian); |
3203
|
186 |
3538
|
187 INSTALL_NCUNOP (op_incr, octave_complex, incr); |
|
188 INSTALL_NCUNOP (op_decr, octave_complex, decr); |
3203
|
189 |
3538
|
190 INSTALL_BINOP (op_add, octave_complex, octave_complex, add); |
|
191 INSTALL_BINOP (op_sub, octave_complex, octave_complex, sub); |
|
192 INSTALL_BINOP (op_mul, octave_complex, octave_complex, mul); |
|
193 INSTALL_BINOP (op_div, octave_complex, octave_complex, div); |
|
194 INSTALL_BINOP (op_pow, octave_complex, octave_complex, pow); |
|
195 INSTALL_BINOP (op_ldiv, octave_complex, octave_complex, ldiv); |
|
196 INSTALL_BINOP (op_lt, octave_complex, octave_complex, lt); |
|
197 INSTALL_BINOP (op_le, octave_complex, octave_complex, le); |
|
198 INSTALL_BINOP (op_eq, octave_complex, octave_complex, eq); |
|
199 INSTALL_BINOP (op_ge, octave_complex, octave_complex, ge); |
|
200 INSTALL_BINOP (op_gt, octave_complex, octave_complex, gt); |
|
201 INSTALL_BINOP (op_ne, octave_complex, octave_complex, ne); |
|
202 INSTALL_BINOP (op_el_mul, octave_complex, octave_complex, el_mul); |
|
203 INSTALL_BINOP (op_el_div, octave_complex, octave_complex, el_div); |
|
204 INSTALL_BINOP (op_el_pow, octave_complex, octave_complex, el_pow); |
|
205 INSTALL_BINOP (op_el_ldiv, octave_complex, octave_complex, el_ldiv); |
|
206 INSTALL_BINOP (op_el_and, octave_complex, octave_complex, el_and); |
|
207 INSTALL_BINOP (op_el_or, octave_complex, octave_complex, el_or); |
2928
|
208 |
4915
|
209 INSTALL_CATOP (octave_complex, octave_complex, cs_cs); |
|
210 |
2928
|
211 INSTALL_ASSIGNCONV (octave_complex, octave_complex, octave_complex_matrix); |
|
212 } |
|
213 |
|
214 /* |
|
215 ;;; Local Variables: *** |
|
216 ;;; mode: C++ *** |
|
217 ;;; End: *** |
|
218 */ |