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 (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 |
3223
|
50 octave_complex : public octave_base_scalar<Complex> |
2376
|
51 { |
|
52 public: |
|
53 |
|
54 octave_complex (void) |
3223
|
55 : octave_base_scalar<Complex> () { } |
2376
|
56 |
|
57 octave_complex (const Complex& c) |
3223
|
58 : octave_base_scalar<Complex> (c) { } |
2376
|
59 |
|
60 octave_complex (const octave_complex& c) |
3223
|
61 : octave_base_scalar<Complex> (c) { } |
2376
|
62 |
|
63 ~octave_complex (void) { } |
|
64 |
3933
|
65 octave_value *clone (void) const { return new octave_complex (*this); } |
4749
|
66 |
|
67 // We return an octave_complex_matrix object here instead of an |
|
68 // octave_complex object so that in expressions like A(2,2,2) = 2 |
|
69 // (for A previously undefined), A will be empty instead of a 1x1 |
|
70 // object. |
|
71 octave_value *empty_clone (void) const |
|
72 { return new octave_complex_matrix (); } |
2376
|
73 |
2410
|
74 octave_value *try_narrowing_conversion (void); |
|
75 |
3933
|
76 octave_value do_index_op (const octave_value_list& idx, int resize_ok); |
2376
|
77 |
5110
|
78 octave_value any (int = 0) const |
|
79 { |
|
80 return (scalar != Complex (0, 0) |
|
81 && ! (lo_ieee_isnan (::real (scalar)) |
|
82 || lo_ieee_isnan (::imag (scalar)))); |
|
83 } |
|
84 |
2376
|
85 bool is_complex_scalar (void) const { return true; } |
|
86 |
|
87 bool is_complex_type (void) const { return true; } |
|
88 |
|
89 // XXX FIXME XXX ??? |
|
90 bool valid_as_scalar_index (void) const { return false; } |
|
91 bool valid_as_zero_index (void) const { return false; } |
|
92 |
|
93 double double_value (bool = false) const; |
|
94 |
3145
|
95 double scalar_value (bool frc_str_conv = false) const |
|
96 { return double_value (frc_str_conv); } |
2916
|
97 |
2376
|
98 Matrix matrix_value (bool = false) const; |
|
99 |
4569
|
100 NDArray array_value (bool = false) const; |
|
101 |
4915
|
102 octave_value resize (const dim_vector& dv) const |
4944
|
103 { |
|
104 ComplexNDArray retval (dv); |
|
105 |
|
106 if (dv.numel ()) |
|
107 retval(0) = scalar; |
|
108 |
|
109 return retval; |
|
110 } |
4915
|
111 |
2376
|
112 Complex complex_value (bool = false) const; |
|
113 |
|
114 ComplexMatrix complex_matrix_value (bool = false) const; |
|
115 |
4569
|
116 ComplexNDArray complex_array_value (bool = false) const; |
|
117 |
2376
|
118 void increment (void) { scalar += 1.0; } |
|
119 |
|
120 void decrement (void) { scalar -= 1.0; } |
|
121 |
4687
|
122 bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
123 bool strip_nan_and_inf); |
|
124 |
|
125 bool load_ascii (std::istream& is); |
|
126 |
|
127 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
128 |
|
129 bool load_binary (std::istream& is, bool swap, |
|
130 oct_mach_info::float_format fmt); |
|
131 |
|
132 #if defined (HAVE_HDF5) |
|
133 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
134 |
|
135 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
136 #endif |
|
137 |
4944
|
138 int write (octave_stream& os, int block_size, |
|
139 oct_data_conv::data_type output_type, int skip, |
|
140 oct_mach_info::float_format flt_fmt) const |
|
141 { |
|
142 // Yes, for compatibility, we drop the imaginary part here. |
|
143 return os.write (array_value (true), block_size, output_type, |
|
144 skip, flt_fmt); |
|
145 } |
|
146 |
2376
|
147 private: |
|
148 |
4612
|
149 DECLARE_OCTAVE_ALLOCATOR |
2477
|
150 |
4612
|
151 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376
|
152 }; |
|
153 |
4953
|
154 typedef octave_complex octave_complex_scalar; |
|
155 |
2376
|
156 #endif |
|
157 |
|
158 /* |
|
159 ;;; Local Variables: *** |
|
160 ;;; mode: C++ *** |
|
161 ;;; End: *** |
|
162 */ |