Mercurial > hg > octave-nkf
annotate src/ov-complex.h @ 10313:f3b65e1ae355
untabify src header files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Feb 2010 12:16:43 -0500 |
parents | cd96d29c5efa |
children | d9e57045b9e1 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
8920 | 4 2007, 2008 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2376 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2376 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_complex_h) | |
25 #define octave_complex_h 1 | |
26 | |
27 #include <cstdlib> | |
28 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
29 #include <iosfwd> |
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 | |
9853
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
37 #include "gripes.h" |
2376 | 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 | |
6693 | 52 OCTINTERP_API |
3223 | 53 octave_complex : public octave_base_scalar<Complex> |
2376 | 54 { |
55 public: | |
56 | |
57 octave_complex (void) | |
3223 | 58 : octave_base_scalar<Complex> () { } |
2376 | 59 |
60 octave_complex (const Complex& c) | |
3223 | 61 : octave_base_scalar<Complex> (c) { } |
2376 | 62 |
63 octave_complex (const octave_complex& c) | |
3223 | 64 : octave_base_scalar<Complex> (c) { } |
2376 | 65 |
66 ~octave_complex (void) { } | |
67 | |
5759 | 68 octave_base_value *clone (void) const { return new octave_complex (*this); } |
4749 | 69 |
70 // We return an octave_complex_matrix object here instead of an | |
71 // octave_complex object so that in expressions like A(2,2,2) = 2 | |
72 // (for A previously undefined), A will be empty instead of a 1x1 | |
73 // object. | |
5759 | 74 octave_base_value *empty_clone (void) const |
4749 | 75 { return new octave_complex_matrix (); } |
2376 | 76 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
77 type_conv_info numeric_demotion_function (void) const; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
78 |
5759 | 79 octave_base_value *try_narrowing_conversion (void); |
2410 | 80 |
5885 | 81 octave_value do_index_op (const octave_value_list& idx, |
10313 | 82 bool resize_ok = false); |
2376 | 83 |
5110 | 84 octave_value any (int = 0) const |
85 { | |
86 return (scalar != Complex (0, 0) | |
10313 | 87 && ! (lo_ieee_isnan (std::real (scalar)) |
88 || lo_ieee_isnan (std::imag (scalar)))); | |
5110 | 89 } |
90 | |
9685 | 91 builtin_type_t builtin_type (void) const { return btyp_complex; } |
92 | |
2376 | 93 bool is_complex_scalar (void) const { return true; } |
94 | |
95 bool is_complex_type (void) const { return true; } | |
96 | |
5895 | 97 bool is_double_type (void) const { return true; } |
98 | |
7576 | 99 bool is_float_type (void) const { return true; } |
100 | |
2376 | 101 double double_value (bool = false) const; |
102 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
103 float float_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
104 |
3145 | 105 double scalar_value (bool frc_str_conv = false) const |
106 { return double_value (frc_str_conv); } | |
2916 | 107 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
108 float float_scalar_value (bool frc_str_conv = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
109 { return float_value (frc_str_conv); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
110 |
2376 | 111 Matrix matrix_value (bool = false) const; |
112 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
113 FloatMatrix float_matrix_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
114 |
4569 | 115 NDArray array_value (bool = false) const; |
116 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
117 FloatNDArray float_array_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
118 |
5989 | 119 SparseMatrix sparse_matrix_value (bool = false) const |
120 { return SparseMatrix (matrix_value ()); } | |
121 | |
122 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const | |
123 { return SparseComplexMatrix (complex_matrix_value ()); } | |
124 | |
5731 | 125 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915 | 126 |
2376 | 127 Complex complex_value (bool = false) const; |
128 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
129 FloatComplex float_complex_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
130 |
2376 | 131 ComplexMatrix complex_matrix_value (bool = false) const; |
132 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
133 FloatComplexMatrix float_complex_matrix_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
134 |
4569 | 135 ComplexNDArray complex_array_value (bool = false) const; |
136 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
137 FloatComplexNDArray float_complex_array_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
138 |
9853
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
139 bool bool_value (bool warn = false) const |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
140 { |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
141 if (xisnan (scalar)) |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
142 error ("invalid conversion from NaN to logical"); |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
143 else if (warn && scalar != 0.0 && scalar != 1.0) |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
144 gripe_logical_conversion (); |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
145 |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
146 return scalar != 0.0; |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
147 } |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
148 |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
149 boolNDArray bool_array_value (bool warn = false) const |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
150 { |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
151 if (xisnan (scalar)) |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
152 error ("invalid conversion from NaN to logical"); |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
153 else if (warn && scalar != 0.0 && scalar != 1.0) |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
154 gripe_logical_conversion (); |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
155 |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
156 return boolNDArray (dim_vector (1, 1), scalar != 0.0); |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
157 } |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
158 |
2376 | 159 void increment (void) { scalar += 1.0; } |
160 | |
161 void decrement (void) { scalar -= 1.0; } | |
162 | |
6974 | 163 bool save_ascii (std::ostream& os); |
4687 | 164 |
165 bool load_ascii (std::istream& is); | |
166 | |
167 bool save_binary (std::ostream& os, bool& save_as_floats); | |
168 | |
169 bool load_binary (std::istream& is, bool swap, | |
10313 | 170 oct_mach_info::float_format fmt); |
4687 | 171 |
172 #if defined (HAVE_HDF5) | |
173 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
174 | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9853
diff
changeset
|
175 bool load_hdf5 (hid_t loc_id, const char *name); |
4687 | 176 #endif |
177 | |
4944 | 178 int write (octave_stream& os, int block_size, |
10313 | 179 oct_data_conv::data_type output_type, int skip, |
180 oct_mach_info::float_format flt_fmt) const | |
4944 | 181 { |
182 // Yes, for compatibility, we drop the imaginary part here. | |
183 return os.write (array_value (true), block_size, output_type, | |
10313 | 184 skip, flt_fmt); |
4944 | 185 } |
186 | |
5900 | 187 mxArray *as_mxArray (void) const; |
188 | |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
189 octave_value map (unary_mapper_t umap) const; |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
190 |
2376 | 191 private: |
192 | |
4612 | 193 DECLARE_OCTAVE_ALLOCATOR |
2477 | 194 |
4612 | 195 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376 | 196 }; |
197 | |
4953 | 198 typedef octave_complex octave_complex_scalar; |
199 | |
2376 | 200 #endif |