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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
2376
|
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/>. |
2376
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_complex_h) |
|
24 #define octave_complex_h 1 |
|
25 |
|
26 #include <cstdlib> |
|
27 |
3503
|
28 #include <iostream> |
2376
|
29 #include <string> |
|
30 |
5110
|
31 #include "lo-ieee.h" |
2376
|
32 #include "mx-base.h" |
2477
|
33 #include "oct-alloc.h" |
2376
|
34 #include "str-vec.h" |
|
35 |
|
36 #include "error.h" |
|
37 #include "ov-base.h" |
4749
|
38 #include "ov-cx-mat.h" |
3223
|
39 #include "ov-base-scalar.h" |
2376
|
40 #include "ov-typeinfo.h" |
|
41 |
|
42 class Octave_map; |
|
43 class octave_value_list; |
|
44 |
|
45 class tree_walker; |
|
46 |
2477
|
47 // Complex scalar values. |
2376
|
48 |
|
49 class |
6693
|
50 OCTINTERP_API |
3223
|
51 octave_complex : public octave_base_scalar<Complex> |
2376
|
52 { |
|
53 public: |
|
54 |
|
55 octave_complex (void) |
3223
|
56 : octave_base_scalar<Complex> () { } |
2376
|
57 |
|
58 octave_complex (const Complex& c) |
3223
|
59 : octave_base_scalar<Complex> (c) { } |
2376
|
60 |
|
61 octave_complex (const octave_complex& c) |
3223
|
62 : octave_base_scalar<Complex> (c) { } |
2376
|
63 |
|
64 ~octave_complex (void) { } |
|
65 |
5759
|
66 octave_base_value *clone (void) const { return new octave_complex (*this); } |
4749
|
67 |
|
68 // We return an octave_complex_matrix object here instead of an |
|
69 // octave_complex object so that in expressions like A(2,2,2) = 2 |
|
70 // (for A previously undefined), A will be empty instead of a 1x1 |
|
71 // object. |
5759
|
72 octave_base_value *empty_clone (void) const |
4749
|
73 { return new octave_complex_matrix (); } |
2376
|
74 |
5759
|
75 octave_base_value *try_narrowing_conversion (void); |
2410
|
76 |
5885
|
77 octave_value do_index_op (const octave_value_list& idx, |
|
78 bool resize_ok = false); |
2376
|
79 |
5110
|
80 octave_value any (int = 0) const |
|
81 { |
|
82 return (scalar != Complex (0, 0) |
6269
|
83 && ! (lo_ieee_isnan (std::real (scalar)) |
|
84 || lo_ieee_isnan (std::imag (scalar)))); |
5110
|
85 } |
|
86 |
2376
|
87 bool is_complex_scalar (void) const { return true; } |
|
88 |
|
89 bool is_complex_type (void) const { return true; } |
|
90 |
5895
|
91 bool is_double_type (void) const { return true; } |
|
92 |
5775
|
93 // FIXME ??? |
2376
|
94 bool valid_as_scalar_index (void) const { return false; } |
|
95 bool valid_as_zero_index (void) const { return false; } |
|
96 |
|
97 double double_value (bool = false) const; |
|
98 |
3145
|
99 double scalar_value (bool frc_str_conv = false) const |
|
100 { return double_value (frc_str_conv); } |
2916
|
101 |
2376
|
102 Matrix matrix_value (bool = false) const; |
|
103 |
4569
|
104 NDArray array_value (bool = false) const; |
|
105 |
5989
|
106 SparseMatrix sparse_matrix_value (bool = false) const |
|
107 { return SparseMatrix (matrix_value ()); } |
|
108 |
|
109 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const |
|
110 { return SparseComplexMatrix (complex_matrix_value ()); } |
|
111 |
5731
|
112 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915
|
113 |
2376
|
114 Complex complex_value (bool = false) const; |
|
115 |
|
116 ComplexMatrix complex_matrix_value (bool = false) const; |
|
117 |
4569
|
118 ComplexNDArray complex_array_value (bool = false) const; |
|
119 |
2376
|
120 void increment (void) { scalar += 1.0; } |
|
121 |
|
122 void decrement (void) { scalar -= 1.0; } |
|
123 |
6974
|
124 bool save_ascii (std::ostream& os); |
4687
|
125 |
|
126 bool load_ascii (std::istream& is); |
|
127 |
|
128 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
129 |
|
130 bool load_binary (std::istream& is, bool swap, |
|
131 oct_mach_info::float_format fmt); |
|
132 |
|
133 #if defined (HAVE_HDF5) |
|
134 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
135 |
|
136 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
137 #endif |
|
138 |
4944
|
139 int write (octave_stream& os, int block_size, |
|
140 oct_data_conv::data_type output_type, int skip, |
|
141 oct_mach_info::float_format flt_fmt) const |
|
142 { |
|
143 // Yes, for compatibility, we drop the imaginary part here. |
|
144 return os.write (array_value (true), block_size, output_type, |
|
145 skip, flt_fmt); |
|
146 } |
|
147 |
5900
|
148 mxArray *as_mxArray (void) const; |
|
149 |
2376
|
150 private: |
|
151 |
4612
|
152 DECLARE_OCTAVE_ALLOCATOR |
2477
|
153 |
4612
|
154 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376
|
155 }; |
|
156 |
4953
|
157 typedef octave_complex octave_complex_scalar; |
|
158 |
2376
|
159 #endif |
|
160 |
|
161 /* |
|
162 ;;; Local Variables: *** |
|
163 ;;; mode: C++ *** |
|
164 ;;; End: *** |
|
165 */ |