Mercurial > hg > octave-nkf
annotate src/ov-complex.h @ 12307:3dc4cfc5a3c1 release-3-4-x
Use pattern-style rules to make .texi files rather than older suffix-style rules.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 30 Jan 2011 22:44:52 -0800 |
parents | 12df7854fa7c |
children | b5e819930fd5 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 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 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
28 #include <iosfwd> |
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 | |
9853
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
36 #include "gripes.h" |
2376 | 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_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 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
75 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
|
76 |
5759 | 77 octave_base_value *try_narrowing_conversion (void); |
2410 | 78 |
5885 | 79 octave_value do_index_op (const octave_value_list& idx, |
10313 | 80 bool resize_ok = false); |
2376 | 81 |
5110 | 82 octave_value any (int = 0) const |
83 { | |
84 return (scalar != Complex (0, 0) | |
10313 | 85 && ! (lo_ieee_isnan (std::real (scalar)) |
86 || lo_ieee_isnan (std::imag (scalar)))); | |
5110 | 87 } |
88 | |
9685 | 89 builtin_type_t builtin_type (void) const { return btyp_complex; } |
90 | |
2376 | 91 bool is_complex_scalar (void) const { return true; } |
92 | |
93 bool is_complex_type (void) const { return true; } | |
94 | |
5895 | 95 bool is_double_type (void) const { return true; } |
96 | |
7576 | 97 bool is_float_type (void) const { return true; } |
98 | |
2376 | 99 double double_value (bool = false) const; |
100 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
101 float float_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
102 |
3145 | 103 double scalar_value (bool frc_str_conv = false) const |
104 { return double_value (frc_str_conv); } | |
2916 | 105 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
106 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
|
107 { return float_value (frc_str_conv); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
108 |
2376 | 109 Matrix matrix_value (bool = false) const; |
110 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
111 FloatMatrix float_matrix_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
112 |
4569 | 113 NDArray array_value (bool = false) const; |
114 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
115 FloatNDArray float_array_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
116 |
5989 | 117 SparseMatrix sparse_matrix_value (bool = false) const |
118 { return SparseMatrix (matrix_value ()); } | |
119 | |
120 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const | |
121 { return SparseComplexMatrix (complex_matrix_value ()); } | |
122 | |
5731 | 123 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915 | 124 |
2376 | 125 Complex complex_value (bool = false) const; |
126 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
127 FloatComplex float_complex_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
128 |
2376 | 129 ComplexMatrix complex_matrix_value (bool = false) const; |
130 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
131 FloatComplexMatrix float_complex_matrix_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
132 |
4569 | 133 ComplexNDArray complex_array_value (bool = false) const; |
134 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
135 FloatComplexNDArray float_complex_array_value (bool = false) const; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
136 |
9853
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
137 bool bool_value (bool warn = false) const |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
138 { |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
139 if (xisnan (scalar)) |
11129
0de5cc44e690
use gripe functions for NaN to logical and NaN to character conversions more consistently
John W. Eaton <jwe@octave.org>
parents:
10759
diff
changeset
|
140 gripe_nan_to_logical_conversion (); |
9853
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
141 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
|
142 gripe_logical_conversion (); |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
143 |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
144 return scalar != 0.0; |
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 |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
147 boolNDArray bool_array_value (bool warn = false) const |
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 if (xisnan (scalar)) |
11129
0de5cc44e690
use gripe functions for NaN to logical and NaN to character conversions more consistently
John W. Eaton <jwe@octave.org>
parents:
10759
diff
changeset
|
150 gripe_nan_to_logical_conversion (); |
9853
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
151 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
|
152 gripe_logical_conversion (); |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
153 |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
154 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
|
155 } |
8d9e4752441a
implement complex built-in logical conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
156 |
2376 | 157 void increment (void) { scalar += 1.0; } |
158 | |
159 void decrement (void) { scalar -= 1.0; } | |
160 | |
6974 | 161 bool save_ascii (std::ostream& os); |
4687 | 162 |
163 bool load_ascii (std::istream& is); | |
164 | |
165 bool save_binary (std::ostream& os, bool& save_as_floats); | |
166 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
167 bool load_binary (std::istream& is, bool swap, |
10313 | 168 oct_mach_info::float_format fmt); |
4687 | 169 |
170 #if defined (HAVE_HDF5) | |
171 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
172 | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9853
diff
changeset
|
173 bool load_hdf5 (hid_t loc_id, const char *name); |
4687 | 174 #endif |
175 | |
4944 | 176 int write (octave_stream& os, int block_size, |
10313 | 177 oct_data_conv::data_type output_type, int skip, |
178 oct_mach_info::float_format flt_fmt) const | |
4944 | 179 { |
180 // Yes, for compatibility, we drop the imaginary part here. | |
181 return os.write (array_value (true), block_size, output_type, | |
10313 | 182 skip, flt_fmt); |
4944 | 183 } |
184 | |
5900 | 185 mxArray *as_mxArray (void) const; |
186 | |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
187 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
|
188 |
2376 | 189 private: |
190 | |
4612 | 191 DECLARE_OCTAVE_ALLOCATOR |
2477 | 192 |
4612 | 193 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2376 | 194 }; |
195 | |
4953 | 196 typedef octave_complex octave_complex_scalar; |
197 | |
2376 | 198 #endif |