2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
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 |
3503
|
31 #include <iostream> |
2901
|
32 |
2376
|
33 #include "lo-ieee.h" |
|
34 |
|
35 #include "oct-obj.h" |
2410
|
36 #include "ops.h" |
2376
|
37 #include "ov-complex.h" |
3223
|
38 #include "ov-base.h" |
|
39 #include "ov-base-scalar.h" |
|
40 #include "ov-base-scalar.cc" |
2423
|
41 #include "ov-cx-mat.h" |
2410
|
42 #include "ov-scalar.h" |
2376
|
43 #include "gripes.h" |
|
44 #include "pr-output.h" |
|
45 |
3223
|
46 template class octave_base_scalar<Complex>; |
|
47 |
3219
|
48 DEFINE_OCTAVE_ALLOCATOR (octave_complex); |
2376
|
49 |
3219
|
50 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_complex, "complex scalar"); |
2376
|
51 |
2410
|
52 octave_value * |
|
53 octave_complex::try_narrowing_conversion (void) |
|
54 { |
|
55 octave_value *retval = 0; |
|
56 |
|
57 if (imag (scalar) == 0.0) |
3775
|
58 retval = new octave_scalar (real (scalar)); |
2410
|
59 |
|
60 return retval; |
|
61 } |
|
62 |
2376
|
63 octave_value |
3933
|
64 octave_complex::do_index_op (const octave_value_list& idx, int resize_ok) |
2376
|
65 { |
|
66 octave_value retval; |
|
67 |
3933
|
68 if (idx.valid_scalar_indices ()) |
2376
|
69 retval = scalar; |
|
70 else |
|
71 { |
|
72 // XXX FIXME XXX -- this doesn't solve the problem of |
|
73 // |
|
74 // a = i; a([1,1], [1,1], [1,1]) |
|
75 // |
|
76 // and similar constructions. Hmm... |
|
77 |
2423
|
78 // XXX FIXME XXX -- using this constructor avoids narrowing the |
|
79 // 1x1 matrix back to a scalar value. Need a better solution |
|
80 // to this problem. |
|
81 |
|
82 octave_value tmp (new octave_complex_matrix (complex_matrix_value ())); |
2376
|
83 |
3933
|
84 retval = tmp.do_index_op (idx, resize_ok); |
2376
|
85 } |
|
86 |
|
87 return retval; |
|
88 } |
|
89 |
|
90 double |
|
91 octave_complex::double_value (bool force_conversion) const |
|
92 { |
|
93 double retval = octave_NaN; |
|
94 |
|
95 int flag = force_conversion; |
|
96 |
|
97 if (! flag) |
|
98 flag = Vok_to_lose_imaginary_part; |
|
99 |
|
100 if (flag < 0) |
|
101 gripe_implicit_conversion ("complex scalar", "real scalar"); |
|
102 |
|
103 if (flag) |
3775
|
104 retval = std::real (scalar); |
2376
|
105 else |
|
106 gripe_invalid_conversion ("complex scalar", "real scalar"); |
|
107 |
|
108 return retval; |
|
109 } |
|
110 |
|
111 Matrix |
|
112 octave_complex::matrix_value (bool force_conversion) const |
|
113 { |
|
114 Matrix retval; |
|
115 |
|
116 int flag = force_conversion; |
|
117 |
|
118 if (! flag) |
|
119 flag = Vok_to_lose_imaginary_part; |
|
120 |
|
121 if (flag < 0) |
|
122 gripe_implicit_conversion ("complex scalar", "real matrix"); |
|
123 |
|
124 if (flag) |
3775
|
125 retval = Matrix (1, 1, std::real (scalar)); |
2376
|
126 else |
|
127 gripe_invalid_conversion ("complex scalar", "real matrix"); |
|
128 |
|
129 return retval; |
|
130 } |
|
131 |
|
132 Complex |
|
133 octave_complex::complex_value (bool) const |
|
134 { |
|
135 return scalar; |
|
136 } |
|
137 |
|
138 |
|
139 ComplexMatrix |
|
140 octave_complex::complex_matrix_value (bool) const |
|
141 { |
|
142 return ComplexMatrix (1, 1, scalar); |
|
143 } |
|
144 |
|
145 /* |
|
146 ;;; Local Variables: *** |
|
147 ;;; mode: C++ *** |
|
148 ;;; End: *** |
|
149 */ |