Mercurial > octave
annotate libinterp/operators/op-cs-s.cc @ 23083:e9a0469dedd9 stable
maint: strip extra trailing newlines from files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 20 Jan 2017 12:19:08 -0500 |
parents | 34ce5be04942 |
children | ef4d915df748 3ac9f9ecfae5 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
3 Copyright (C) 1996-2016 John W. Eaton |
2928 | 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 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21647
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
2928 | 25 #endif |
26 | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
27 #include "errwarn.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
28 #include "ovl.h" |
2928 | 29 #include "ov.h" |
30 #include "ov-complex.h" | |
31 #include "ov-cx-mat.h" | |
32 #include "ov-scalar.h" | |
33 #include "ov-typeinfo.h" | |
34 #include "ops.h" | |
35 #include "xdiv.h" | |
36 #include "xpow.h" | |
37 | |
38 // complex scalar by scalar ops. | |
39 | |
40 DEFBINOP_OP (add, complex, scalar, +) | |
41 DEFBINOP_OP (sub, complex, scalar, -) | |
42 DEFBINOP_OP (mul, complex, scalar, *) | |
43 | |
44 DEFBINOP (div, complex, scalar) | |
45 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
46 const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1); |
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
47 const octave_scalar& v2 = dynamic_cast<const octave_scalar&> (a2); |
2928 | 48 |
49 double d = v2.double_value (); | |
50 | |
51 if (d == 0.0) | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
52 warn_divide_by_zero (); |
2928 | 53 |
54 return octave_value (v1.complex_value () / d); | |
55 } | |
56 | |
57 DEFBINOP_FN (pow, complex, scalar, xpow) | |
58 | |
59 DEFBINOP (ldiv, complex, scalar) | |
60 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
61 const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1); |
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
62 const octave_scalar& v2 = dynamic_cast<const octave_scalar&> (a2); |
2928 | 63 |
3055 | 64 Complex d = v1.complex_value (); |
2928 | 65 |
66 if (d == 0.0) | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
67 warn_divide_by_zero (); |
2928 | 68 |
3054 | 69 return octave_value (v2.double_value () / d); |
2928 | 70 } |
71 | |
9621
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
72 DEFCMPLXCMPOP_OP (lt, complex, scalar, <) |
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
73 DEFCMPLXCMPOP_OP (le, complex, scalar, <=) |
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
74 DEFCMPLXCMPOP_OP (eq, complex, scalar, ==) |
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
75 DEFCMPLXCMPOP_OP (ge, complex, scalar, >=) |
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
76 DEFCMPLXCMPOP_OP (gt, complex, scalar, >) |
3ee9029931b3
fix scalar complex-real comparisons
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
77 DEFCMPLXCMPOP_OP (ne, complex, scalar, !=) |
2928 | 78 |
79 DEFBINOP_OP (el_mul, complex, scalar, *) | |
80 | |
81 DEFBINOP (el_div, complex, scalar) | |
82 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
83 const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1); |
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
84 const octave_scalar& v2 = dynamic_cast<const octave_scalar&> (a2); |
2928 | 85 |
86 double d = v2.double_value (); | |
87 | |
88 if (d == 0.0) | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
89 warn_divide_by_zero (); |
2928 | 90 |
91 return octave_value (v1.complex_value () / d); | |
92 } | |
93 | |
94 DEFBINOP_FN (el_pow, complex, scalar, xpow) | |
95 | |
96 DEFBINOP (el_ldiv, complex, scalar) | |
97 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
98 const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1); |
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
99 const octave_scalar& v2 = dynamic_cast<const octave_scalar&> (a2); |
2928 | 100 |
4502 | 101 Complex d = v1.complex_value (); |
2928 | 102 |
103 if (d == 0.0) | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
104 warn_divide_by_zero (); |
2928 | 105 |
4502 | 106 return octave_value (v2.double_value () / d); |
2928 | 107 } |
108 | |
109 DEFBINOP (el_and, complex, scalar) | |
110 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
111 const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1); |
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
112 const octave_scalar& v2 = dynamic_cast<const octave_scalar&> (a2); |
2928 | 113 |
114 return v1.complex_value () != 0.0 && v2.double_value (); | |
115 } | |
116 | |
117 DEFBINOP (el_or, complex, scalar) | |
118 { | |
21647
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
119 const octave_complex& v1 = dynamic_cast<const octave_complex&> (a1); |
66cae7a6dc47
eliminate some macros for operator definitions
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
120 const octave_scalar& v2 = dynamic_cast<const octave_scalar&> (a2); |
2928 | 121 |
122 return v1.complex_value () != 0.0 || v2.double_value (); | |
123 } | |
124 | |
4915 | 125 DEFNDCATOP_FN (cs_s, complex, scalar, complex_array, array, concat) |
126 | |
2928 | 127 void |
128 install_cs_s_ops (void) | |
129 { | |
3538 | 130 INSTALL_BINOP (op_add, octave_complex, octave_scalar, add); |
131 INSTALL_BINOP (op_sub, octave_complex, octave_scalar, sub); | |
132 INSTALL_BINOP (op_mul, octave_complex, octave_scalar, mul); | |
133 INSTALL_BINOP (op_div, octave_complex, octave_scalar, div); | |
134 INSTALL_BINOP (op_pow, octave_complex, octave_scalar, pow); | |
135 INSTALL_BINOP (op_ldiv, octave_complex, octave_scalar, ldiv); | |
136 INSTALL_BINOP (op_lt, octave_complex, octave_scalar, lt); | |
137 INSTALL_BINOP (op_le, octave_complex, octave_scalar, le); | |
138 INSTALL_BINOP (op_eq, octave_complex, octave_scalar, eq); | |
139 INSTALL_BINOP (op_ge, octave_complex, octave_scalar, ge); | |
140 INSTALL_BINOP (op_gt, octave_complex, octave_scalar, gt); | |
141 INSTALL_BINOP (op_ne, octave_complex, octave_scalar, ne); | |
142 INSTALL_BINOP (op_el_mul, octave_complex, octave_scalar, el_mul); | |
143 INSTALL_BINOP (op_el_div, octave_complex, octave_scalar, el_div); | |
144 INSTALL_BINOP (op_el_pow, octave_complex, octave_scalar, el_pow); | |
145 INSTALL_BINOP (op_el_ldiv, octave_complex, octave_scalar, el_ldiv); | |
146 INSTALL_BINOP (op_el_and, octave_complex, octave_scalar, el_and); | |
147 INSTALL_BINOP (op_el_or, octave_complex, octave_scalar, el_or); | |
2928 | 148 |
4915 | 149 INSTALL_CATOP (octave_complex, octave_scalar, cs_s); |
150 | |
2928 | 151 INSTALL_ASSIGNCONV (octave_complex, octave_scalar, octave_complex_matrix); |
152 } |