comparison libinterp/octave-value/ov-complex.h @ 15195:2fc554ffbc28

split libinterp from src * libinterp: New directory. Move all files from src directory here except Makefile.am, main.cc, main-cli.cc, mkoctfile.in.cc, mkoctfilr.in.sh, octave-config.in.cc, octave-config.in.sh. * libinterp/Makefile.am: New file, extracted from src/Makefile.am. * src/Makefile.am: Delete everything except targets and definitions needed to build and link main and utility programs. * Makefile.am (SUBDIRS): Include libinterp in the list. * autogen.sh: Run config-module.sh in libinterp/dldfcn directory, not src/dldfcn directory. * configure.ac (AC_CONFIG_SRCDIR): Use libinterp/octave.cc, not src/octave.cc. (DL_LDFLAGS, LIBOCTINTERP): Use libinterp, not src. (AC_CONFIG_FILES): Include libinterp/Makefile in the list. * find-docstring-files.sh: Look in libinterp, not src. * gui/src/Makefile.am (liboctgui_la_CPPFLAGS): Find header files in libinterp, not src.
author John W. Eaton <jwe@octave.org>
date Sat, 18 Aug 2012 16:23:39 -0400
parents src/octave-value/ov-complex.h@46b19589b593
children
comparison
equal deleted inserted replaced
15194:0f0b795044c3 15195:2fc554ffbc28
1 /*
2
3 Copyright (C) 1996-2012 John W. Eaton
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20
21 */
22
23 #if !defined (octave_complex_h)
24 #define octave_complex_h 1
25
26 #include <cstdlib>
27
28 #include <iosfwd>
29 #include <string>
30
31 #include "lo-ieee.h"
32 #include "mx-base.h"
33 #include "oct-alloc.h"
34 #include "str-vec.h"
35
36 #include "gripes.h"
37 #include "error.h"
38 #include "ov-base.h"
39 #include "ov-cx-mat.h"
40 #include "ov-base-scalar.h"
41 #include "ov-typeinfo.h"
42
43 class octave_value_list;
44
45 class tree_walker;
46
47 // Complex scalar values.
48
49 class
50 OCTINTERP_API
51 octave_complex : public octave_base_scalar<Complex>
52 {
53 public:
54
55 octave_complex (void)
56 : octave_base_scalar<Complex> () { }
57
58 octave_complex (const Complex& c)
59 : octave_base_scalar<Complex> (c) { }
60
61 octave_complex (const octave_complex& c)
62 : octave_base_scalar<Complex> (c) { }
63
64 ~octave_complex (void) { }
65
66 octave_base_value *clone (void) const { return new octave_complex (*this); }
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_base_value *empty_clone (void) const
73 { return new octave_complex_matrix (); }
74
75 type_conv_info numeric_demotion_function (void) const;
76
77 octave_base_value *try_narrowing_conversion (void);
78
79 octave_value do_index_op (const octave_value_list& idx,
80 bool resize_ok = false);
81
82 // Use this to give a more specific error message
83 idx_vector index_vector (void) const
84 {
85 error (
86 "attempted to use a complex scalar as an index\n"
87 " (forgot to initialize i or j?)");
88 return idx_vector ();
89 }
90
91 octave_value any (int = 0) const
92 {
93 return (scalar != Complex (0, 0)
94 && ! (lo_ieee_isnan (std::real (scalar))
95 || lo_ieee_isnan (std::imag (scalar))));
96 }
97
98 builtin_type_t builtin_type (void) const { return btyp_complex; }
99
100 bool is_complex_scalar (void) const { return true; }
101
102 bool is_complex_type (void) const { return true; }
103
104 bool is_double_type (void) const { return true; }
105
106 bool is_float_type (void) const { return true; }
107
108 double double_value (bool = false) const;
109
110 float float_value (bool = false) const;
111
112 double scalar_value (bool frc_str_conv = false) const
113 { return double_value (frc_str_conv); }
114
115 float float_scalar_value (bool frc_str_conv = false) const
116 { return float_value (frc_str_conv); }
117
118 Matrix matrix_value (bool = false) const;
119
120 FloatMatrix float_matrix_value (bool = false) const;
121
122 NDArray array_value (bool = false) const;
123
124 FloatNDArray float_array_value (bool = false) const;
125
126 SparseMatrix sparse_matrix_value (bool = false) const
127 { return SparseMatrix (matrix_value ()); }
128
129 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const
130 { return SparseComplexMatrix (complex_matrix_value ()); }
131
132 octave_value resize (const dim_vector& dv, bool fill = false) const;
133
134 Complex complex_value (bool = false) const;
135
136 FloatComplex float_complex_value (bool = false) const;
137
138 ComplexMatrix complex_matrix_value (bool = false) const;
139
140 FloatComplexMatrix float_complex_matrix_value (bool = false) const;
141
142 ComplexNDArray complex_array_value (bool = false) const;
143
144 FloatComplexNDArray float_complex_array_value (bool = false) const;
145
146 bool bool_value (bool warn = false) const
147 {
148 if (xisnan (scalar))
149 gripe_nan_to_logical_conversion ();
150 else if (warn && scalar != 0.0 && scalar != 1.0)
151 gripe_logical_conversion ();
152
153 return scalar != 0.0;
154 }
155
156 boolNDArray bool_array_value (bool warn = false) const
157 {
158 if (xisnan (scalar))
159 gripe_nan_to_logical_conversion ();
160 else if (warn && scalar != 0.0 && scalar != 1.0)
161 gripe_logical_conversion ();
162
163 return boolNDArray (dim_vector (1, 1), scalar != 0.0);
164 }
165
166 octave_value diag (octave_idx_type m, octave_idx_type n) const;
167
168 void increment (void) { scalar += 1.0; }
169
170 void decrement (void) { scalar -= 1.0; }
171
172 bool save_ascii (std::ostream& os);
173
174 bool load_ascii (std::istream& is);
175
176 bool save_binary (std::ostream& os, bool& save_as_floats);
177
178 bool load_binary (std::istream& is, bool swap,
179 oct_mach_info::float_format fmt);
180
181 #if defined (HAVE_HDF5)
182 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
183
184 bool load_hdf5 (hid_t loc_id, const char *name);
185 #endif
186
187 int write (octave_stream& os, int block_size,
188 oct_data_conv::data_type output_type, int skip,
189 oct_mach_info::float_format flt_fmt) const
190 {
191 // Yes, for compatibility, we drop the imaginary part here.
192 return os.write (array_value (true), block_size, output_type,
193 skip, flt_fmt);
194 }
195
196 mxArray *as_mxArray (void) const;
197
198 octave_value map (unary_mapper_t umap) const;
199
200 private:
201
202 DECLARE_OCTAVE_ALLOCATOR
203
204 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
205 };
206
207 typedef octave_complex octave_complex_scalar;
208
209 #endif