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