comparison src/OPERATORS/op-cs-s.cc @ 2928:295f037b4b3e

[project @ 1997-05-05 05:32:33 by jwe]
author jwe
date Mon, 05 May 1997 05:33:54 +0000
parents
children 788799701ecb
comparison
equal deleted inserted replaced
2927:8722c6284b72 2928:295f037b4b3e
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
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
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
18 along with Octave; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 */
22
23 #if defined (__GNUG__)
24 #pragma implementation
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 #include "gripes.h"
32 #include "ov.h"
33 #include "ov-complex.h"
34 #include "ov-cx-mat.h"
35 #include "ov-scalar.h"
36 #include "ov-typeinfo.h"
37 #include "ops.h"
38 #include "xdiv.h"
39 #include "xpow.h"
40
41 // complex scalar by scalar ops.
42
43 DEFBINOP_OP (add, complex, scalar, +)
44 DEFBINOP_OP (sub, complex, scalar, -)
45 DEFBINOP_OP (mul, complex, scalar, *)
46
47 DEFBINOP (div, complex, scalar)
48 {
49 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
50
51 double d = v2.double_value ();
52
53 if (d == 0.0)
54 gripe_divide_by_zero ();
55
56 return octave_value (v1.complex_value () / d);
57 }
58
59 DEFBINOP_FN (pow, complex, scalar, xpow)
60
61 DEFBINOP (ldiv, complex, scalar)
62 {
63 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
64
65 double d = v1.double_value ();
66
67 if (d == 0.0)
68 gripe_divide_by_zero ();
69
70 return octave_value (v2.complex_value () / d);
71 }
72
73 DEFBINOP (lt, complex, scalar)
74 {
75 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
76
77 return real (v1.complex_value ()) < v2.double_value ();
78 }
79
80 DEFBINOP (le, complex, scalar)
81 {
82 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
83
84 return real (v1.complex_value ()) <= v2.double_value ();
85 }
86
87 DEFBINOP (eq, complex, scalar)
88 {
89 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
90
91 return v1.complex_value () == v2.double_value ();
92 }
93
94 DEFBINOP (ge, complex, scalar)
95 {
96 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
97
98 return real (v1.complex_value ()) >= v2.double_value ();
99 }
100
101 DEFBINOP (gt, complex, scalar)
102 {
103 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
104
105 return real (v1.complex_value ()) > v2.double_value ();
106 }
107
108 DEFBINOP (ne, complex, scalar)
109 {
110 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
111
112 return v1.complex_value () != v2.double_value ();
113 }
114
115 DEFBINOP_OP (el_mul, complex, scalar, *)
116
117 DEFBINOP (el_div, complex, scalar)
118 {
119 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
120
121 double d = v2.double_value ();
122
123 if (d == 0.0)
124 gripe_divide_by_zero ();
125
126 return octave_value (v1.complex_value () / d);
127 }
128
129 DEFBINOP_FN (el_pow, complex, scalar, xpow)
130
131 DEFBINOP (el_ldiv, complex, scalar)
132 {
133 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
134
135 double d = v1.double_value ();
136
137 if (d == 0.0)
138 gripe_divide_by_zero ();
139
140 return octave_value (v2.complex_value () / d);
141 }
142
143 DEFBINOP (el_and, complex, scalar)
144 {
145 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
146
147 return v1.complex_value () != 0.0 && v2.double_value ();
148 }
149
150 DEFBINOP (el_or, complex, scalar)
151 {
152 CAST_BINOP_ARGS (const octave_complex&, const octave_scalar&);
153
154 return v1.complex_value () != 0.0 || v2.double_value ();
155 }
156
157 DEFCONV (complex_matrix_conv, complex, complex_matrix)
158 {
159 CAST_CONV_ARG (const octave_complex&);
160
161 return new octave_complex_matrix (v.complex_matrix_value ());
162 }
163
164 void
165 install_cs_s_ops (void)
166 {
167 INSTALL_BINOP (add, octave_complex, octave_scalar, add);
168 INSTALL_BINOP (sub, octave_complex, octave_scalar, sub);
169 INSTALL_BINOP (mul, octave_complex, octave_scalar, mul);
170 INSTALL_BINOP (div, octave_complex, octave_scalar, div);
171 INSTALL_BINOP (pow, octave_complex, octave_scalar, pow);
172 INSTALL_BINOP (ldiv, octave_complex, octave_scalar, ldiv);
173 INSTALL_BINOP (lt, octave_complex, octave_scalar, lt);
174 INSTALL_BINOP (le, octave_complex, octave_scalar, le);
175 INSTALL_BINOP (eq, octave_complex, octave_scalar, eq);
176 INSTALL_BINOP (ge, octave_complex, octave_scalar, ge);
177 INSTALL_BINOP (gt, octave_complex, octave_scalar, gt);
178 INSTALL_BINOP (ne, octave_complex, octave_scalar, ne);
179 INSTALL_BINOP (el_mul, octave_complex, octave_scalar, el_mul);
180 INSTALL_BINOP (el_div, octave_complex, octave_scalar, el_div);
181 INSTALL_BINOP (el_pow, octave_complex, octave_scalar, el_pow);
182 INSTALL_BINOP (el_ldiv, octave_complex, octave_scalar, el_ldiv);
183 INSTALL_BINOP (el_and, octave_complex, octave_scalar, el_and);
184 INSTALL_BINOP (el_or, octave_complex, octave_scalar, el_or);
185
186 INSTALL_ASSIGNCONV (octave_complex, octave_scalar, octave_complex_matrix);
187
188 INSTALL_WIDENOP (octave_complex, octave_complex_matrix, complex_matrix_conv);
189 }
190
191 /*
192 ;;; Local Variables: ***
193 ;;; mode: C++ ***
194 ;;; End: ***
195 */