00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_float_h)
00025 #define octave_float_h 1
00026
00027 #include <cstdlib>
00028
00029 #include <iosfwd>
00030 #include <string>
00031
00032 #include "lo-ieee.h"
00033 #include "lo-mappers.h"
00034 #include "lo-utils.h"
00035 #include "mx-base.h"
00036 #include "oct-alloc.h"
00037 #include "str-vec.h"
00038
00039 #include "gripes.h"
00040 #include "ov-base.h"
00041 #include "ov-re-mat.h"
00042 #include "ov-flt-re-mat.h"
00043 #include "ov-base-scalar.h"
00044 #include "ov-typeinfo.h"
00045
00046 class Octave_map;
00047 class octave_value_list;
00048
00049 class tree_walker;
00050
00051
00052
00053 class
00054 OCTINTERP_API
00055 octave_float_scalar : public octave_base_scalar<float>
00056 {
00057 public:
00058
00059 octave_float_scalar (void)
00060 : octave_base_scalar<float> (0.0) { }
00061
00062 octave_float_scalar (float d)
00063 : octave_base_scalar<float> (d) { }
00064
00065 octave_float_scalar (const octave_float_scalar& s)
00066 : octave_base_scalar<float> (s) { }
00067
00068 ~octave_float_scalar (void) { }
00069
00070 octave_base_value *clone (void) const { return new octave_float_scalar (*this); }
00071
00072
00073
00074
00075 octave_base_value *empty_clone (void) const { return new octave_matrix (); }
00076
00077 octave_value do_index_op (const octave_value_list& idx,
00078 bool resize_ok = false);
00079
00080 idx_vector index_vector (void) const { return idx_vector (scalar); }
00081
00082 octave_value any (int = 0) const
00083 { return (scalar != 0 && ! lo_ieee_isnan (scalar)); }
00084
00085 builtin_type_t builtin_type (void) const { return btyp_float; }
00086
00087 bool is_real_scalar (void) const { return true; }
00088
00089 bool is_real_type (void) const { return true; }
00090
00091 bool is_single_type (void) const { return true; }
00092
00093 bool is_float_type (void) const { return true; }
00094
00095 int8NDArray
00096 int8_array_value (void) const
00097 { return int8NDArray (dim_vector (1, 1), scalar); }
00098
00099 int16NDArray
00100 int16_array_value (void) const
00101 { return int16NDArray (dim_vector (1, 1), scalar); }
00102
00103 int32NDArray
00104 int32_array_value (void) const
00105 { return int32NDArray (dim_vector (1, 1), scalar); }
00106
00107 int64NDArray
00108 int64_array_value (void) const
00109 { return int64NDArray (dim_vector (1, 1), scalar); }
00110
00111 uint8NDArray
00112 uint8_array_value (void) const
00113 { return uint8NDArray (dim_vector (1, 1), scalar); }
00114
00115 uint16NDArray
00116 uint16_array_value (void) const
00117 { return uint16NDArray (dim_vector (1, 1), scalar); }
00118
00119 uint32NDArray
00120 uint32_array_value (void) const
00121 { return uint32NDArray (dim_vector (1, 1), scalar); }
00122
00123 uint64NDArray
00124 uint64_array_value (void) const
00125 { return uint64NDArray (dim_vector (1, 1), scalar); }
00126
00127 #define DEFINE_INT_SCALAR_VALUE(TYPE) \
00128 octave_ ## TYPE \
00129 TYPE ## _scalar_value (void) const \
00130 { return octave_ ## TYPE (scalar); }
00131
00132 DEFINE_INT_SCALAR_VALUE (int8)
00133 DEFINE_INT_SCALAR_VALUE (int16)
00134 DEFINE_INT_SCALAR_VALUE (int32)
00135 DEFINE_INT_SCALAR_VALUE (int64)
00136 DEFINE_INT_SCALAR_VALUE (uint8)
00137 DEFINE_INT_SCALAR_VALUE (uint16)
00138 DEFINE_INT_SCALAR_VALUE (uint32)
00139 DEFINE_INT_SCALAR_VALUE (uint64)
00140
00141 #undef DEFINE_INT_SCALAR_VALUE
00142
00143 double double_value (bool = false) const { return static_cast<double> (scalar); }
00144
00145 float float_value (bool = false) const { return scalar; }
00146
00147 double scalar_value (bool = false) const { return static_cast<double> (scalar); }
00148
00149 float float_scalar_value (bool = false) const { return scalar; }
00150
00151 Matrix matrix_value (bool = false) const
00152 { return Matrix (1, 1, scalar); }
00153
00154 FloatMatrix float_matrix_value (bool = false) const
00155 { return FloatMatrix (1, 1, scalar); }
00156
00157 NDArray array_value (bool = false) const
00158 { return NDArray (dim_vector (1, 1), scalar); }
00159
00160 FloatNDArray float_array_value (bool = false) const
00161 { return FloatNDArray (dim_vector (1, 1), scalar); }
00162
00163 SparseMatrix sparse_matrix_value (bool = false) const
00164 { return SparseMatrix (Matrix (1, 1, scalar)); }
00165
00166
00167 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const
00168 { return SparseComplexMatrix (sparse_matrix_value ()); }
00169
00170 octave_value resize (const dim_vector& dv, bool fill = false) const;
00171
00172 Complex complex_value (bool = false) const { return scalar; }
00173
00174 FloatComplex float_complex_value (bool = false) const { return scalar; }
00175
00176 ComplexMatrix complex_matrix_value (bool = false) const
00177 { return ComplexMatrix (1, 1, Complex (scalar)); }
00178
00179 FloatComplexMatrix float_complex_matrix_value (bool = false) const
00180 { return FloatComplexMatrix (1, 1, FloatComplex (scalar)); }
00181
00182 ComplexNDArray complex_array_value (bool = false) const
00183 { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); }
00184
00185 FloatComplexNDArray float_complex_array_value (bool = false) const
00186 { return FloatComplexNDArray (dim_vector (1, 1), FloatComplex (scalar)); }
00187
00188 charNDArray
00189 char_array_value (bool = false) const
00190 {
00191 charNDArray retval (dim_vector (1, 1));
00192 retval(0) = static_cast<char> (scalar);
00193 return retval;
00194 }
00195
00196 bool bool_value (bool warn = false) const
00197 {
00198 if (xisnan (scalar))
00199 error ("invalid conversion from NaN to logical");
00200 else if (warn && scalar != 0 && scalar != 1)
00201 gripe_logical_conversion ();
00202
00203 return scalar;
00204 }
00205
00206 boolNDArray bool_array_value (bool warn = false) const
00207 {
00208 if (xisnan (scalar))
00209 error ("invalid conversion from NaN to logical");
00210 else if (warn && scalar != 0 && scalar != 1)
00211 gripe_logical_conversion ();
00212
00213 return boolNDArray (dim_vector (1, 1), scalar);
00214 }
00215
00216 octave_value convert_to_str_internal (bool pad, bool force, char type) const;
00217
00218 void increment (void) { ++scalar; }
00219
00220 void decrement (void) { --scalar; }
00221
00222 bool save_ascii (std::ostream& os);
00223
00224 bool load_ascii (std::istream& is);
00225
00226 bool save_binary (std::ostream& os, bool& save_as_floats);
00227
00228 bool load_binary (std::istream& is, bool swap,
00229 oct_mach_info::float_format fmt);
00230
00231 #if defined (HAVE_HDF5)
00232 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
00233
00234 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug);
00235 #endif
00236
00237 int write (octave_stream& os, int block_size,
00238 oct_data_conv::data_type output_type, int skip,
00239 oct_mach_info::float_format flt_fmt) const
00240 {
00241 return os.write (array_value (), block_size, output_type,
00242 skip, flt_fmt);
00243 }
00244
00245 mxArray *as_mxArray (void) const;
00246
00247 octave_value erf (void) const;
00248 octave_value erfc (void) const;
00249 octave_value gamma (void) const;
00250 octave_value lgamma (void) const;
00251 octave_value abs (void) const;
00252 octave_value acos (void) const;
00253 octave_value acosh (void) const;
00254 octave_value angle (void) const;
00255 octave_value arg (void) const;
00256 octave_value asin (void) const;
00257 octave_value asinh (void) const;
00258 octave_value atan (void) const;
00259 octave_value atanh (void) const;
00260 octave_value ceil (void) const;
00261 octave_value conj (void) const;
00262 octave_value cos (void) const;
00263 octave_value cosh (void) const;
00264 octave_value exp (void) const;
00265 octave_value expm1 (void) const;
00266 octave_value fix (void) const;
00267 octave_value floor (void) const;
00268 octave_value imag (void) const;
00269 octave_value log (void) const;
00270 octave_value log2 (void) const;
00271 octave_value log10 (void) const;
00272 octave_value log1p (void) const;
00273 octave_value real (void) const;
00274 octave_value round (void) const;
00275 octave_value roundb (void) const;
00276 octave_value signum (void) const;
00277 octave_value sin (void) const;
00278 octave_value sinh (void) const;
00279 octave_value sqrt (void) const;
00280 octave_value tan (void) const;
00281 octave_value tanh (void) const;
00282 octave_value finite (void) const;
00283 octave_value isinf (void) const;
00284 octave_value isna (void) const;
00285 octave_value isnan (void) const;
00286
00287 private:
00288 octave_value map (float (*fcn) (float)) const;
00289
00290 DECLARE_OCTAVE_ALLOCATOR
00291
00292 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
00293 };
00294
00295 #endif
00296
00297
00298
00299
00300
00301