GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_lo_utils_h)
27 #define octave_lo_utils_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cstdio>
32 
33 #include <iosfwd>
34 #include <string>
35 
36 #include "lo-cutils.h"
37 #include "oct-cmplx.h"
38 #include "quit.h"
39 
40 // Generic any/all test functionality with arbitrary predicate.
41 
42 template <typename F, typename T, bool zero>
43 bool
44 any_all_test (F fcn, const T *m, octave_idx_type len)
45 {
47 
48  for (i = 0; i < len - 3; i += 4)
49  {
50  octave_quit ();
51 
52  if (fcn (m[i]) != zero
53  || fcn (m[i+1]) != zero
54  || fcn (m[i+2]) != zero
55  || fcn (m[i+3]) != zero)
56  return ! zero;
57  }
58 
59  octave_quit ();
60 
61  for (; i < len; i++)
62  if (fcn (m[i]) != zero)
63  return ! zero;
64 
65  return zero;
66 }
67 
68 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
69 extern OCTAVE_API bool xis_one_or_zero (double x);
70 extern OCTAVE_API bool xis_zero (double x);
71 extern OCTAVE_API bool xtoo_large_for_float (double x);
72 
73 extern OCTAVE_API bool xtoo_large_for_float (const Complex& x);
74 
75 extern OCTAVE_API bool xis_int_or_inf_or_nan (float x);
76 extern OCTAVE_API bool xis_one_or_zero (float x);
77 extern OCTAVE_API bool xis_zero (float x);
78 extern OCTAVE_API bool xtoo_large_for_float (float x);
79 
80 extern OCTAVE_API char * strsave (const char *);
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
122 octave_read_float_complex (std::istream& is)
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
F77_RET_T const F77_DBLE * x
OCTAVE_API void octave_write_complex(std::ostream &os, const Complex &cval)
Definition: lo-utils.cc:400
OCTAVE_API bool xtoo_large_for_float(double x)
Definition: lo-utils.cc:55
OCTAVE_API bool xis_zero(double x)
Definition: lo-utils.cc:52
float octave_read_float(std::istream &is)
Definition: lo-utils.h:116
OCTAVE_API std::string octave_fgets(std::FILE *)
double octave_read_double(std::istream &is)
Definition: lo-utils.h:104
OCTAVE_API void octave_write_double(std::ostream &os, double dval)
Definition: lo-utils.cc:387
OCTAVE_API std::string octave_fgetl(std::FILE *)
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:49
OCTAVE_API bool xis_int_or_inf_or_nan(double x)
Definition: lo-utils.cc:46
OCTAVE_API void octave_write_float_complex(std::ostream &os, const FloatComplex &cval)
Definition: lo-utils.cc:423
OCTAVE_API char * strsave(const char *)
Definition: lo-utils.cc:79
OCTAVE_API void octave_write_float(std::ostream &os, float dval)
Definition: lo-utils.cc:410
T octave_read_value(std::istream &is)
Definition: lo-utils.h:90
bool any_all_test(F fcn, const T *m, octave_idx_type len)
Definition: lo-utils.h:44
FloatComplex octave_read_float_complex(std::istream &is)
Definition: lo-utils.h:122
T octave_idx_type m
Definition: mx-inlines.cc:773
std::complex< double > Complex
Definition: oct-cmplx.h:33
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
F77_RET_T len
Definition: xerbla.cc:61