Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_complex_h)
00024 #define octave_complex_h 1
00025
00026 #include <cstdlib>
00027
00028 #include <iosfwd>
00029 #include <string>
00030
00031 #include "lo-ieee.h"
00032 #include "mx-base.h"
00033 #include "oct-alloc.h"
00034 #include "str-vec.h"
00035
00036 #include "gripes.h"
00037 #include "error.h"
00038 #include "ov-base.h"
00039 #include "ov-cx-mat.h"
00040 #include "ov-base-scalar.h"
00041 #include "ov-typeinfo.h"
00042
00043 class octave_value_list;
00044
00045 class tree_walker;
00046
00047
00048
00049 class
00050 OCTINTERP_API
00051 octave_complex : public octave_base_scalar<Complex>
00052 {
00053 public:
00054
00055 octave_complex (void)
00056 : octave_base_scalar<Complex> () { }
00057
00058 octave_complex (const Complex& c)
00059 : octave_base_scalar<Complex> (c) { }
00060
00061 octave_complex (const octave_complex& c)
00062 : octave_base_scalar<Complex> (c) { }
00063
00064 ~octave_complex (void) { }
00065
00066 octave_base_value *clone (void) const { return new octave_complex (*this); }
00067
00068
00069
00070
00071
00072 octave_base_value *empty_clone (void) const
00073 { return new octave_complex_matrix (); }
00074
00075 type_conv_info numeric_demotion_function (void) const;
00076
00077 octave_base_value *try_narrowing_conversion (void);
00078
00079 octave_value do_index_op (const octave_value_list& idx,
00080 bool resize_ok = false);
00081
00082 octave_value any (int = 0) const
00083 {
00084 return (scalar != Complex (0, 0)
00085 && ! (lo_ieee_isnan (std::real (scalar))
00086 || lo_ieee_isnan (std::imag (scalar))));
00087 }
00088
00089 builtin_type_t builtin_type (void) const { return btyp_complex; }
00090
00091 bool is_complex_scalar (void) const { return true; }
00092
00093 bool is_complex_type (void) const { return true; }
00094
00095 bool is_double_type (void) const { return true; }
00096
00097 bool is_float_type (void) const { return true; }
00098
00099 double double_value (bool = false) const;
00100
00101 float float_value (bool = false) const;
00102
00103 double scalar_value (bool frc_str_conv = false) const
00104 { return double_value (frc_str_conv); }
00105
00106 float float_scalar_value (bool frc_str_conv = false) const
00107 { return float_value (frc_str_conv); }
00108
00109 Matrix matrix_value (bool = false) const;
00110
00111 FloatMatrix float_matrix_value (bool = false) const;
00112
00113 NDArray array_value (bool = false) const;
00114
00115 FloatNDArray float_array_value (bool = false) const;
00116
00117 SparseMatrix sparse_matrix_value (bool = false) const
00118 { return SparseMatrix (matrix_value ()); }
00119
00120 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const
00121 { return SparseComplexMatrix (complex_matrix_value ()); }
00122
00123 octave_value resize (const dim_vector& dv, bool fill = false) const;
00124
00125 Complex complex_value (bool = false) const;
00126
00127 FloatComplex float_complex_value (bool = false) const;
00128
00129 ComplexMatrix complex_matrix_value (bool = false) const;
00130
00131 FloatComplexMatrix float_complex_matrix_value (bool = false) const;
00132
00133 ComplexNDArray complex_array_value (bool = false) const;
00134
00135 FloatComplexNDArray float_complex_array_value (bool = false) const;
00136
00137 bool bool_value (bool warn = false) const
00138 {
00139 if (xisnan (scalar))
00140 gripe_nan_to_logical_conversion ();
00141 else if (warn && scalar != 0.0 && scalar != 1.0)
00142 gripe_logical_conversion ();
00143
00144 return scalar != 0.0;
00145 }
00146
00147 boolNDArray bool_array_value (bool warn = false) const
00148 {
00149 if (xisnan (scalar))
00150 gripe_nan_to_logical_conversion ();
00151 else if (warn && scalar != 0.0 && scalar != 1.0)
00152 gripe_logical_conversion ();
00153
00154 return boolNDArray (dim_vector (1, 1), scalar != 0.0);
00155 }
00156
00157 void increment (void) { scalar += 1.0; }
00158
00159 void decrement (void) { scalar -= 1.0; }
00160
00161 bool save_ascii (std::ostream& os);
00162
00163 bool load_ascii (std::istream& is);
00164
00165 bool save_binary (std::ostream& os, bool& save_as_floats);
00166
00167 bool load_binary (std::istream& is, bool swap,
00168 oct_mach_info::float_format fmt);
00169
00170 #if defined (HAVE_HDF5)
00171 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
00172
00173 bool load_hdf5 (hid_t loc_id, const char *name);
00174 #endif
00175
00176 int write (octave_stream& os, int block_size,
00177 oct_data_conv::data_type output_type, int skip,
00178 oct_mach_info::float_format flt_fmt) const
00179 {
00180
00181 return os.write (array_value (true), block_size, output_type,
00182 skip, flt_fmt);
00183 }
00184
00185 mxArray *as_mxArray (void) const;
00186
00187 octave_value map (unary_mapper_t umap) const;
00188
00189 private:
00190
00191 DECLARE_OCTAVE_ALLOCATOR
00192
00193 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00194 };
00195
00196 typedef octave_complex octave_complex_scalar;
00197
00198 #endif