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 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
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 |
4612
|
50 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_complex, |
|
51 "complex scalar", "double"); |
2376
|
52 |
2410
|
53 octave_value * |
|
54 octave_complex::try_narrowing_conversion (void) |
|
55 { |
|
56 octave_value *retval = 0; |
|
57 |
|
58 if (imag (scalar) == 0.0) |
3775
|
59 retval = new octave_scalar (real (scalar)); |
2410
|
60 |
|
61 return retval; |
|
62 } |
|
63 |
2376
|
64 octave_value |
3933
|
65 octave_complex::do_index_op (const octave_value_list& idx, int resize_ok) |
2376
|
66 { |
|
67 octave_value retval; |
|
68 |
3933
|
69 if (idx.valid_scalar_indices ()) |
2376
|
70 retval = scalar; |
|
71 else |
|
72 { |
|
73 // XXX FIXME XXX -- this doesn't solve the problem of |
|
74 // |
|
75 // a = i; a([1,1], [1,1], [1,1]) |
|
76 // |
|
77 // and similar constructions. Hmm... |
|
78 |
2423
|
79 // XXX FIXME XXX -- using this constructor avoids narrowing the |
|
80 // 1x1 matrix back to a scalar value. Need a better solution |
|
81 // to this problem. |
|
82 |
|
83 octave_value tmp (new octave_complex_matrix (complex_matrix_value ())); |
2376
|
84 |
3933
|
85 retval = tmp.do_index_op (idx, resize_ok); |
2376
|
86 } |
|
87 |
|
88 return retval; |
|
89 } |
|
90 |
|
91 double |
|
92 octave_complex::double_value (bool force_conversion) const |
|
93 { |
4102
|
94 double retval = lo_ieee_nan_value (); |
2376
|
95 |
4451
|
96 if (! force_conversion && Vwarn_imag_to_real) |
2376
|
97 gripe_implicit_conversion ("complex scalar", "real scalar"); |
|
98 |
4451
|
99 retval = std::real (scalar); |
2376
|
100 |
|
101 return retval; |
|
102 } |
|
103 |
|
104 Matrix |
|
105 octave_complex::matrix_value (bool force_conversion) const |
|
106 { |
|
107 Matrix retval; |
|
108 |
4451
|
109 if (! force_conversion && Vwarn_imag_to_real) |
2376
|
110 gripe_implicit_conversion ("complex scalar", "real matrix"); |
|
111 |
4451
|
112 retval = Matrix (1, 1, std::real (scalar)); |
2376
|
113 |
|
114 return retval; |
|
115 } |
|
116 |
4569
|
117 NDArray |
|
118 octave_complex::array_value (bool force_conversion) const |
|
119 { |
|
120 NDArray retval; |
|
121 |
|
122 if (! force_conversion && Vwarn_imag_to_real) |
|
123 gripe_implicit_conversion ("complex scalar", "real matrix"); |
|
124 |
|
125 retval = NDArray (dim_vector (1, 1), std::real (scalar)); |
|
126 |
|
127 return retval; |
|
128 } |
|
129 |
2376
|
130 Complex |
|
131 octave_complex::complex_value (bool) const |
|
132 { |
|
133 return scalar; |
|
134 } |
|
135 |
|
136 |
|
137 ComplexMatrix |
|
138 octave_complex::complex_matrix_value (bool) const |
|
139 { |
|
140 return ComplexMatrix (1, 1, scalar); |
|
141 } |
|
142 |
4569
|
143 ComplexNDArray |
4664
|
144 octave_complex::complex_array_value (bool /* force_conversion */) const |
4569
|
145 { |
|
146 return ComplexNDArray (dim_vector (1, 1), scalar); |
|
147 } |
|
148 |
2376
|
149 /* |
|
150 ;;; Local Variables: *** |
|
151 ;;; mode: C++ *** |
|
152 ;;; End: *** |
|
153 */ |