GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-float.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 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_ov_float_h)
24 #define octave_ov_float_h 1
25 
26 #include <cstdlib>
27 
28 #include <iosfwd>
29 #include <string>
30 
31 #include "lo-ieee.h"
32 #include "lo-mappers.h"
33 #include "lo-utils.h"
34 #include "mx-base.h"
35 #include "str-vec.h"
36 
37 #include "gripes.h"
38 #include "ov-base.h"
39 #include "ov-re-mat.h"
40 #include "ov-flt-re-mat.h"
41 #include "ov-base-scalar.h"
42 #include "ov-typeinfo.h"
43 
44 class octave_value_list;
45 
46 class tree_walker;
47 
48 // Real scalar values.
49 
50 class
53 {
54 public:
55 
57  : octave_base_scalar<float> (0.0) { }
58 
60  : octave_base_scalar<float> (d) { }
61 
63  : octave_base_scalar<float> (s) { }
64 
66 
67  octave_base_value *clone (void) const
68  { return new octave_float_scalar (*this); }
69 
70  // We return an octave_matrix here instead of an octave_float_scalar so
71  // that in expressions like A(2,2,2) = 2 (for A previously
72  // undefined), A will be empty instead of a 1x1 object.
74  { return new octave_float_matrix (); }
75 
76  octave_value do_index_op (const octave_value_list& idx,
77  bool resize_ok = false);
78 
79  idx_vector index_vector (bool /* require_integers */ = false) const { return idx_vector (scalar); }
80 
81  octave_value any (int = 0) const
82  { return (scalar != 0 && ! lo_ieee_isnan (scalar)); }
83 
84  builtin_type_t builtin_type (void) const { return btyp_float; }
85 
86  bool is_real_scalar (void) const { return true; }
87 
88  bool is_real_type (void) const { return true; }
89 
90  bool is_single_type (void) const { return true; }
91 
92  bool is_float_type (void) const { return true; }
93 
95  int8_array_value (void) const
96  { return int8NDArray (dim_vector (1, 1), scalar); }
97 
99  int16_array_value (void) const
100  { return int16NDArray (dim_vector (1, 1), scalar); }
101 
103  int32_array_value (void) const
104  { return int32NDArray (dim_vector (1, 1), scalar); }
105 
107  int64_array_value (void) const
108  { return int64NDArray (dim_vector (1, 1), scalar); }
109 
111  uint8_array_value (void) const
112  { return uint8NDArray (dim_vector (1, 1), scalar); }
113 
115  uint16_array_value (void) const
116  { return uint16NDArray (dim_vector (1, 1), scalar); }
117 
119  uint32_array_value (void) const
120  { return uint32NDArray (dim_vector (1, 1), scalar); }
121 
123  uint64_array_value (void) const
124  { return uint64NDArray (dim_vector (1, 1), scalar); }
125 
126 #define DEFINE_INT_SCALAR_VALUE(TYPE) \
127  octave_ ## TYPE \
128  TYPE ## _scalar_value (void) const \
129  { return octave_ ## TYPE (scalar); }
130 
139 
140 #undef DEFINE_INT_SCALAR_VALUE
141 
142  double double_value (bool = false) const
143  { return static_cast<double> (scalar); }
144 
145  float float_value (bool = false) const { return scalar; }
146 
147  double scalar_value (bool = false) const
148  { return static_cast<double> (scalar); }
149 
150  float float_scalar_value (bool = false) const { return scalar; }
151 
152  Matrix matrix_value (bool = false) const
153  { return Matrix (1, 1, scalar); }
154 
155  FloatMatrix float_matrix_value (bool = false) const
156  { return FloatMatrix (1, 1, scalar); }
157 
158  NDArray array_value (bool = false) const
159  { return NDArray (dim_vector (1, 1), scalar); }
160 
161  FloatNDArray float_array_value (bool = false) const
162  { return FloatNDArray (dim_vector (1, 1), scalar); }
163 
164  SparseMatrix sparse_matrix_value (bool = false) const
165  { return SparseMatrix (Matrix (1, 1, scalar)); }
166 
167  // FIXME Need SparseComplexMatrix (Matrix) constructor!!!
169  { return SparseComplexMatrix (sparse_matrix_value ()); }
170 
171  octave_value resize (const dim_vector& dv, bool fill = false) const;
172 
173  Complex complex_value (bool = false) const { return scalar; }
174 
175  FloatComplex float_complex_value (bool = false) const { return scalar; }
176 
177  ComplexMatrix complex_matrix_value (bool = false) const
178  { return ComplexMatrix (1, 1, Complex (scalar)); }
179 
181  { return FloatComplexMatrix (1, 1, FloatComplex (scalar)); }
182 
183  ComplexNDArray complex_array_value (bool = false) const
184  { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); }
185 
187  { return FloatComplexNDArray (dim_vector (1, 1), FloatComplex (scalar)); }
188 
190  char_array_value (bool = false) const
191  {
192  charNDArray retval (dim_vector (1, 1));
193  retval(0) = static_cast<char> (scalar);
194  return retval;
195  }
196 
197  bool bool_value (bool warn = false) const
198  {
199  if (xisnan (scalar))
201  else if (warn && scalar != 0 && scalar != 1)
203 
204  return scalar;
205  }
206 
207  boolNDArray bool_array_value (bool warn = false) const
208  {
209  if (xisnan (scalar))
211  else if (warn && scalar != 0 && scalar != 1)
213 
214  return boolNDArray (dim_vector (1, 1), scalar);
215  }
216 
217  octave_value diag (octave_idx_type m, octave_idx_type n) const;
218 
219  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
220 
221  void increment (void) { ++scalar; }
222 
223  void decrement (void) { --scalar; }
224 
225  bool save_ascii (std::ostream& os);
226 
227  bool load_ascii (std::istream& is);
228 
229  bool save_binary (std::ostream& os, bool& save_as_floats);
230 
231  bool load_binary (std::istream& is, bool swap,
233 
234  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
235 
236  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
237 
238  int write (octave_stream& os, int block_size,
239  oct_data_conv::data_type output_type, int skip,
240  oct_mach_info::float_format flt_fmt) const
241  {
242  return os.write (array_value (), block_size, output_type,
243  skip, flt_fmt);
244  }
245 
246  mxArray *as_mxArray (void) const;
247 
248  octave_value map (unary_mapper_t umap) const;
249 
250  bool fast_elem_insert_self (void *where, builtin_type_t btyp) const;
251 
252 private:
253 
254 
256 };
257 
258 #endif
bool is_float_type(void) const
Definition: ov-float.h:92
int64NDArray int64_array_value(void) const
Definition: ov-float.h:107
FloatNDArray float_array_value(bool=false) const
Definition: ov-float.h:161
int8NDArray int8_array_value(void) const
Definition: ov-float.h:95
uint8NDArray uint8_array_value(void) const
Definition: ov-float.h:111
intNDArray< octave_int64 > int64NDArray
Definition: int64NDArray.h:31
boolNDArray bool_array_value(bool warn=false) const
Definition: ov-float.h:207
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-float.h:164
bool xisnan(double x)
Definition: lo-mappers.cc:144
void decrement(void)
Definition: ov-float.h:223
intNDArray< octave_uint32 > uint32NDArray
Definition: uint32NDArray.h:31
Complex complex_value(bool=false) const
Definition: ov-float.h:173
intNDArray< octave_uint8 > uint8NDArray
Definition: uint8NDArray.h:31
intNDArray< octave_uint16 > uint16NDArray
Definition: uint16NDArray.h:31
bool is_real_type(void) const
Definition: ov-float.h:88
octave_float_scalar(float d)
Definition: ov-float.h:59
~octave_float_scalar(void)
Definition: ov-float.h:65
bool is_single_type(void) const
Definition: ov-float.h:90
int32NDArray int32_array_value(void) const
Definition: ov-float.h:103
FloatMatrix float_matrix_value(bool=false) const
Definition: ov-float.h:155
float float_value(bool=false) const
Definition: ov-float.h:145
intNDArray< octave_int16 > int16NDArray
Definition: int16NDArray.h:31
builtin_type_t
Definition: ov-base.h:59
uint64NDArray uint64_array_value(void) const
Definition: ov-float.h:123
builtin_type_t builtin_type(void) const
Definition: ov-float.h:84
F77_RET_T const double const double double * d
#define lo_ieee_isnan(x)
Definition: lo-ieee.h:101
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-float.h:183
octave_base_value * empty_clone(void) const
Definition: ov-float.h:73
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-float.h:177
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:142
bool is_real_scalar(void) const
Definition: ov-float.h:86
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-float.h:168
#define OCTINTERP_API
Definition: mexproto.h:66
intNDArray< octave_int8 > int8NDArray
Definition: int8NDArray.h:31
octave_base_value * clone(void) const
Definition: ov-float.h:67
bool bool_value(bool warn=false) const
Definition: ov-float.h:197
void gripe_nan_to_logical_conversion(void)
Matrix matrix_value(bool=false) const
Definition: ov-float.h:152
int write(octave_stream &os, int block_size, oct_data_conv::data_type output_type, int skip, oct_mach_info::float_format flt_fmt) const
Definition: ov-float.h:238
FloatComplexNDArray float_complex_array_value(bool=false) const
Definition: ov-float.h:186
#define DEFINE_INT_SCALAR_VALUE(TYPE)
Definition: ov-float.h:126
Definition: dMatrix.h:35
idx_vector index_vector(bool=false) const
Definition: ov-float.h:79
void increment(void)
Definition: ov-float.h:221
float float_scalar_value(bool=false) const
Definition: ov-float.h:150
intNDArray< octave_int32 > int32NDArray
Definition: int32NDArray.h:31
void gripe_logical_conversion(void)
Definition: gripes.cc:201
FloatComplexMatrix float_complex_matrix_value(bool=false) const
Definition: ov-float.h:180
uint16NDArray uint16_array_value(void) const
Definition: ov-float.h:115
FloatComplex float_complex_value(bool=false) const
Definition: ov-float.h:175
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, oct_mach_info::float_format flt_fmt)
Definition: oct-stream.cc:3546
int16NDArray int16_array_value(void) const
Definition: ov-float.h:99
octave_value any(int=0) const
Definition: ov-float.h:81
std::complex< float > FloatComplex
Definition: oct-cmplx.h:30
std::complex< double > Complex
Definition: oct-cmplx.h:29
charNDArray char_array_value(bool=false) const
Definition: ov-float.h:190
double double_value(bool=false) const
Definition: ov-float.h:142
octave_float_scalar(const octave_float_scalar &s)
Definition: ov-float.h:62
NDArray array_value(bool=false) const
Definition: ov-float.h:158
octave_float_scalar(void)
Definition: ov-float.h:56
double scalar_value(bool=false) const
Definition: ov-float.h:147
static bool scalar(const dim_vector &dims)
Definition: ov-struct.cc:736
uint32NDArray uint32_array_value(void) const
Definition: ov-float.h:119
intNDArray< octave_uint64 > uint64NDArray
Definition: uint64NDArray.h:31