5260
|
1 #define OCTAVE_STD std |
2376
|
2 /* |
|
3 |
2847
|
4 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_complex_h) |
|
25 #define octave_complex_h 1 |
|
26 |
|
27 #include <cstdlib> |
|
28 |
3503
|
29 #include <iostream> |
2376
|
30 #include <string> |
|
31 |
5110
|
32 #include "lo-ieee.h" |
2376
|
33 #include "mx-base.h" |
2477
|
34 #include "oct-alloc.h" |
2376
|
35 #include "str-vec.h" |
|
36 |
|
37 #include "error.h" |
|
38 #include "ov-base.h" |
4749
|
39 #include "ov-cx-mat.h" |
3223
|
40 #include "ov-base-scalar.h" |
2376
|
41 #include "ov-typeinfo.h" |
|
42 |
|
43 class Octave_map; |
|
44 class octave_value_list; |
|
45 |
|
46 class tree_walker; |
|
47 |
2477
|
48 // Complex scalar values. |
2376
|
49 |
|
50 class |
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 |
3933
|
66 octave_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. |
|
72 octave_value *empty_clone (void) const |
|
73 { return new octave_complex_matrix (); } |
2376
|
74 |
2410
|
75 octave_value *try_narrowing_conversion (void); |
|
76 |
3933
|
77 octave_value do_index_op (const octave_value_list& idx, int resize_ok); |
2376
|
78 |
5110
|
79 octave_value any (int = 0) const |
|
80 { |
|
81 return (scalar != Complex (0, 0) |
5260
|
82 && ! (lo_ieee_isnan (OCTAVE_STD::real (scalar)) |
|
83 || lo_ieee_isnan (OCTAVE_STD::imag (scalar)))); |
5110
|
84 } |
|
85 |
2376
|
86 bool is_complex_scalar (void) const { return true; } |
|
87 |
|
88 bool is_complex_type (void) const { return true; } |
|
89 |
|
90 // XXX FIXME XXX ??? |
|
91 bool valid_as_scalar_index (void) const { return false; } |
|
92 bool valid_as_zero_index (void) const { return false; } |
|
93 |
|
94 double double_value (bool = false) const; |
|
95 |
3145
|
96 double scalar_value (bool frc_str_conv = false) const |
|
97 { return double_value (frc_str_conv); } |
2916
|
98 |
2376
|
99 Matrix matrix_value (bool = false) const; |
|
100 |
4569
|
101 NDArray array_value (bool = false) const; |
|
102 |
4915
|
103 octave_value resize (const dim_vector& dv) const |
4944
|
104 { |
|
105 ComplexNDArray retval (dv); |
|
106 |
|
107 if (dv.numel ()) |
|
108 retval(0) = scalar; |
|
109 |
|
110 return retval; |
|
111 } |
4915
|
112 |
2376
|
113 Complex complex_value (bool = false) const; |
|
114 |
|
115 ComplexMatrix complex_matrix_value (bool = false) const; |
|
116 |
4569
|
117 ComplexNDArray complex_array_value (bool = false) const; |
|
118 |
2376
|
119 void increment (void) { scalar += 1.0; } |
|
120 |
|
121 void decrement (void) { scalar -= 1.0; } |
|
122 |
4687
|
123 bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
124 bool strip_nan_and_inf); |
|
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 |
2376
|
148 private: |
|
149 |
4612
|
150 DECLARE_OCTAVE_ALLOCATOR |
2477
|
151 |
4612
|
152 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376
|
153 }; |
|
154 |
4953
|
155 typedef octave_complex octave_complex_scalar; |
|
156 |
2376
|
157 #endif |
|
158 |
|
159 /* |
|
160 ;;; Local Variables: *** |
|
161 ;;; mode: C++ *** |
|
162 ;;; End: *** |
|
163 */ |