GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
lo-utils.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_lo_utils_h)
24 #define octave_lo_utils_h 1
25 
26 #include "octave-config.h"
27 
28 #include <cstdio>
29 
30 #include <iostream>
31 #include <string>
32 
33 #include "lo-cutils.h"
34 #include "oct-cmplx.h"
35 #include "quit.h"
36 
37 // Generic any/all test functionality with arbitrary predicate.
38 
39 template <typename F, typename T, bool zero>
40 bool
41 any_all_test (F fcn, const T *m, octave_idx_type len)
42 {
44 
45  for (i = 0; i < len - 3; i += 4)
46  {
47  octave_quit ();
48 
49  if (fcn (m[i]) != zero
50  || fcn (m[i+1]) != zero
51  || fcn (m[i+2]) != zero
52  || fcn (m[i+3]) != zero)
53  return ! zero;
54  }
55 
56  octave_quit ();
57 
58  for (; i < len; i++)
59  if (fcn (m[i]) != zero)
60  return ! zero;
61 
62  return zero;
63 }
64 
65 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
66 extern OCTAVE_API bool xis_one_or_zero (double x);
67 extern OCTAVE_API bool xis_zero (double x);
68 extern OCTAVE_API bool xtoo_large_for_float (double x);
69 
70 extern OCTAVE_API bool xtoo_large_for_float (const Complex& x);
71 
72 extern OCTAVE_API bool xis_int_or_inf_or_nan (float x);
73 extern OCTAVE_API bool xis_one_or_zero (float x);
74 extern OCTAVE_API bool xis_zero (float x);
75 extern OCTAVE_API bool xtoo_large_for_float (float x);
76 
77 extern OCTAVE_API char * strsave (const char *);
78 
79 extern OCTAVE_API void
80 octave_putenv (const std::string&, const std::string&);
81 
82 extern OCTAVE_API std::string octave_fgets (std::FILE *);
83 extern OCTAVE_API std::string octave_fgetl (std::FILE *);
84 
85 extern OCTAVE_API std::string octave_fgets (std::FILE *, bool& eof);
86 extern OCTAVE_API std::string octave_fgetl (std::FILE *, bool& eof);
87 
88 template <typename T>
89 T
90 octave_read_value (std::istream& is)
91 {
92  T retval;
93  is >> retval;
94  return retval;
95 }
96 
97 template <> OCTAVE_API double octave_read_value (std::istream& is);
98 template <> OCTAVE_API Complex octave_read_value (std::istream& is);
99 template <> OCTAVE_API float octave_read_value (std::istream& is);
100 template <> OCTAVE_API FloatComplex octave_read_value (std::istream& is);
101 
102 // The next four functions are provided for backward compatibility.
103 inline double
104 octave_read_double (std::istream& is)
105 {
106  return octave_read_value<double> (is);
107 }
108 
109 inline Complex
110 octave_read_complex (std::istream& is)
111 {
112  return octave_read_value<Complex> (is);
113 }
114 
115 inline float
116 octave_read_float (std::istream& is)
117 {
118  return octave_read_value<float> (is);
119 }
120 
121 inline FloatComplex
123 {
124  return octave_read_value<FloatComplex> (is);
125 }
126 
127 extern OCTAVE_API void
128 octave_write_double (std::ostream& os, double dval);
129 
130 extern OCTAVE_API void
131 octave_write_complex (std::ostream& os, const Complex& cval);
132 
133 extern OCTAVE_API void
134 octave_write_float (std::ostream& os, float dval);
135 
136 extern OCTAVE_API void
137 octave_write_float_complex (std::ostream& os, const FloatComplex& cval);
138 
139 #endif
OCTAVE_API void octave_write_float(std::ostream &os, float dval)
Definition: lo-utils.cc:418
double octave_read_double(std::istream &is)
Definition: lo-utils.h:104
bool any_all_test(F fcn, const T *m, octave_idx_type len)
Definition: lo-utils.h:41
OCTAVE_API void octave_write_double(std::ostream &os, double dval)
Definition: lo-utils.cc:395
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by zero($0/0$)
OCTAVE_API std::string octave_fgetl(std::FILE *)
octave_function * fcn
Definition: ov-class.cc:1754
Complex octave_read_complex(std::istream &is)
Definition: lo-utils.h:110
OCTAVE_API bool xis_one_or_zero(double x)
Definition: lo-utils.cc:45
OCTAVE_API void octave_write_float_complex(std::ostream &os, const FloatComplex &cval)
Definition: lo-utils.cc:431
octave_value retval
Definition: data.cc:6246
OCTAVE_API char * strsave(const char *)
Definition: lo-utils.cc:75
OCTAVE_API bool xis_zero(double x)
Definition: lo-utils.cc:48
OCTAVE_API void octave_putenv(const std::string &, const std::string &)
Definition: lo-utils.cc:92
OCTAVE_API bool xis_int_or_inf_or_nan(double x)
Definition: lo-utils.cc:42
OCTAVE_API void octave_write_complex(std::ostream &os, const Complex &cval)
Definition: lo-utils.cc:408
FloatComplex octave_read_float_complex(std::istream &is)
Definition: lo-utils.h:122
for i
Definition: data.cc:5264
T octave_read_value(std::istream &is)
Definition: lo-utils.h:90
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
std::complex< double > Complex
Definition: oct-cmplx.h:31
OCTAVE_API bool xtoo_large_for_float(double x)
Definition: lo-utils.cc:51
write the output to stdout if nargout is
Definition: load-save.cc:1612
OCTAVE_API std::string octave_fgets(std::FILE *)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
octave::stream os
Definition: file-io.cc:627
float octave_read_float(std::istream &is)
Definition: lo-utils.h:116
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
void F(const TSRC *v, TRES *r, octave_idx_type m, octave_idx_type n)
Definition: mx-inlines.cc:756