GNU Octave 7.1.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-2022 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
40namespace octave
41{
42 // Generic any/all test functionality with arbitrary predicate.
43
44 template <typename F, typename T, bool zero>
45 bool
46 any_all_test (F fcn, const T *m, octave_idx_type len)
47 {
49
50 for (i = 0; i < len - 3; i += 4)
51 {
52 octave_quit ();
53
54 if (fcn (m[i]) != zero
55 || fcn (m[i+1]) != zero
56 || fcn (m[i+2]) != zero
57 || fcn (m[i+3]) != zero)
58 return ! zero;
59 }
60
61 octave_quit ();
62
63 for (; i < len; i++)
64 if (fcn (m[i]) != zero)
65 return ! zero;
66
67 return zero;
68 }
69
70 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
71
72 template <typename T>
73 bool is_one_or_zero (const T& x)
74 {
75 return x == T (0) || x == T (1);
76 }
77
78 template <typename T>
79 bool is_zero (const T& x)
80 {
81 return x == T (0);
82 }
83
84 extern OCTAVE_API bool too_large_for_float (double x);
85
86 extern OCTAVE_API bool too_large_for_float (const Complex& x);
87
88 extern OCTAVE_API bool is_int_or_inf_or_nan (float x);
89 extern OCTAVE_API bool too_large_for_float (float x);
90
91 extern OCTAVE_API char * strsave (const char *);
92
93 extern OCTAVE_API std::string fgets (std::FILE *);
94 extern OCTAVE_API std::string fgetl (std::FILE *);
95
96 extern OCTAVE_API std::string fgets (std::FILE *, bool& eof);
97 extern OCTAVE_API std::string fgetl (std::FILE *, bool& eof);
98
99 template <typename T> OCTAVE_API T read_value (std::istream& is);
100
101 template <> OCTAVE_API double read_value (std::istream& is);
102 template <> OCTAVE_API Complex read_value (std::istream& is);
103 template <> OCTAVE_API float read_value (std::istream& is);
104 template <> OCTAVE_API FloatComplex read_value (std::istream& is);
105
106 template <typename T> OCTAVE_API void write_value (std::ostream& os, const T& value);
107
108 template <> OCTAVE_API void write_value (std::ostream& os, const double& value);
109 template <> OCTAVE_API void write_value (std::ostream& os, const Complex& value);
110 template <> OCTAVE_API void write_value (std::ostream& os, const float& value);
111 template <> OCTAVE_API void write_value (std::ostream& os, const FloatComplex& value);
112
113 namespace math
114 {
115 extern OCTAVE_API bool int_multiply_overflow (int a, int b, int *r);
116
117 extern OCTAVE_API bool
118 int_multiply_overflow (long int a, long int b, long int *r);
119
120#if defined (OCTAVE_HAVE_LONG_LONG_INT)
121 extern OCTAVE_API bool
122 int_multiply_overflow (long long int a, long long int b, long long int *r);
123#endif
124
125 extern OCTAVE_API bool
126 int_multiply_overflow (unsigned int a, unsigned int b, unsigned int *r);
127
128 extern OCTAVE_API bool
129 int_multiply_overflow (unsigned long int a, unsigned long int b,
130 unsigned long int *r);
131
132#if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
133 extern OCTAVE_API bool
134 int_multiply_overflow (unsigned long long int a, unsigned long long int b,
135 unsigned long long int *r);
136#endif
137 }
138}
139
140#if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
141template <typename F, typename T, bool zero>
142OCTAVE_DEPRECATED (7, "use 'octave::any_all_test' instead")
143bool
144any_all_test (F fcn, const T *m, octave_idx_type len)
145{
146 return octave::any_all_test<F, T, zero> (fcn, m, len);
147}
148
149OCTAVE_DEPRECATED (7, "use 'octave::is_int_or_inf_or_nan' instead")
150inline bool xis_int_or_inf_or_nan (double x)
151{
153}
154
155template <typename T>
156OCTAVE_DEPRECATED (7, "use 'octave::is_one_or_zero' instead")
157bool
158xis_one_or_zero (const T& x)
159{
160 return octave::is_one_or_zero (x);
161}
162
163template <typename T>
164OCTAVE_DEPRECATED (7, "use 'octave::is_zero' instead")
165bool
166xis_zero (const T& x)
167{
168 return octave::is_zero (x);
169}
170
171OCTAVE_DEPRECATED (7, "use 'octave::' instead")
172inline bool xtoo_large_for_float (double x)
173{
175}
176
177OCTAVE_DEPRECATED (7, "use 'octave::' instead")
178inline bool xtoo_large_for_float (const Complex& x)
179{
181}
182
183OCTAVE_DEPRECATED (7, "use 'octave::' instead")
184inline bool xis_int_or_inf_or_nan (float x)
185{
187}
188
189OCTAVE_DEPRECATED (7, "use 'octave::' instead")
190inline bool xtoo_large_for_float (float x)
191{
193}
194
195OCTAVE_DEPRECATED (7, "use 'octave::strsave' instead")
196inline char * strsave (const char *s)
197{
198 return octave::strsave (s);
199}
200
201OCTAVE_DEPRECATED (7, "use 'octave::fgets' instead")
202inline std::string octave_fgets (std::FILE *f)
203{
204 return octave::fgets (f);
205}
206
207OCTAVE_DEPRECATED (7, "use 'octave::fgetl' instead")
208inline std::string octave_fgetl (std::FILE *f)
209{
210 return octave::fgetl (f);
211}
212
213OCTAVE_DEPRECATED (7, "use 'octave::fgets' instead")
214inline std::string octave_fgets (std::FILE *f, bool& eof)
215{
216 return octave::fgets (f, eof);
217}
218
219OCTAVE_DEPRECATED (7, "use 'octave::fgetl' instead")
220inline std::string octave_fgetl (std::FILE *f, bool& eof)
221{
222 return octave::fgetl (f, eof);
223}
224
225OCTAVE_DEPRECATED (7, "use 'octave::read_value<T>' instead")
226inline double
227octave_read_double (std::istream& is)
228{
229 return octave::read_value<double> (is);
230}
231
232OCTAVE_DEPRECATED (7, "use 'octave::read_value<T>' instead")
233inline Complex
234octave_read_complex (std::istream& is)
235{
236 return octave::read_value<Complex> (is);
237}
238
239OCTAVE_DEPRECATED (7, "use 'octave::read_value<T>' instead")
240inline float
241octave_read_float (std::istream& is)
242{
243 return octave::read_value<float> (is);
244}
245
246OCTAVE_DEPRECATED (7, "use 'octave::read_value<T>' instead")
247inline FloatComplex
248octave_read_float_complex (std::istream& is)
249{
250 return octave::read_value<FloatComplex> (is);
251}
252
253OCTAVE_DEPRECATED (7, "use 'octave::write_value<T>' instead")
254inline void
255octave_write_double (std::ostream& os, double value)
256{
257 octave::write_value<double> (os, value);
258}
259
260OCTAVE_DEPRECATED (7, "use 'octave::write_value<T>' instead")
261inline void
262octave_write_complex (std::ostream& os, const Complex& value)
263{
264 octave::write_value<Complex> (os, value);
265}
266
267OCTAVE_DEPRECATED (7, "use 'octave::write_value<T>' instead")
268inline void
269octave_write_float (std::ostream& os, float value)
270{
271 octave::write_value<float> (os, value);
272}
273
274OCTAVE_DEPRECATED (7, "use 'octave::write_value<T>' instead")
275inline void
276octave_write_float_complex (std::ostream& os, const FloatComplex& value)
277{
278 octave::write_value<FloatComplex> (os, value);
279}
280#endif
281
282#endif
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f
static char * strsave(const char *s)
Definition: main.in.cc:214
#define OCTAVE_API
Definition: main.in.cc:55
void F(const TSRC *v, TRES *r, octave_idx_type m, octave_idx_type n)
Definition: mx-inlines.cc:757
bool int_multiply_overflow(int a, int b, int *r)
Definition: lo-utils.cc:480
std::string fgets(FILE *f)
Definition: lo-utils.cc:85
bool is_int_or_inf_or_nan(double x)
Definition: lo-utils.cc:50
char * strsave(const char *s)
Definition: lo-utils.cc:74
std::string fgetl(FILE *f)
Definition: lo-utils.cc:165
bool any_all_test(F fcn, const T *m, octave_idx_type len)
Definition: lo-utils.h:46
OCTAVE_API bool xis_int_or_inf_or_nan(double x)
T read_value(std::istream &is)
Definition: lo-utils.cc:183
bool is_zero(const T &x)
Definition: lo-utils.h:79
bool is_one_or_zero(const T &x)
Definition: lo-utils.h:73
void write_value(std::ostream &os, const T &value)
Definition: lo-utils.cc:402
bool too_large_for_float(double x)
Definition: lo-utils.cc:55
STL namespace.
std::complex< double > Complex
Definition: oct-cmplx.h:33
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
F77_RET_T len
Definition: xerbla.cc:61