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