GNU Octave  9.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-2024 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 "oct-cmplx.h"
37 #include "quit.h"
38 
40 
41 // Generic any/all test functionality with arbitrary predicate.
42 
43 template <typename F, typename T, bool zero>
44 bool
45 any_all_test (F fcn, const T *m, octave_idx_type len)
46 {
48 
49  for (i = 0; i < len - 3; i += 4)
50  {
51  octave_quit ();
52 
53  if (fcn (m[i]) != zero
54  || fcn (m[i+1]) != zero
55  || fcn (m[i+2]) != zero
56  || fcn (m[i+3]) != zero)
57  return ! zero;
58  }
59 
60  octave_quit ();
61 
62  for (; i < len; i++)
63  if (fcn (m[i]) != zero)
64  return ! zero;
65 
66  return zero;
67 }
68 
69 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
70 
71 template <typename T>
72 bool is_one_or_zero (const T& x)
73 {
74  return x == T (0) || x == T (1);
75 }
76 
77 template <typename T>
78 bool is_zero (const T& x)
79 {
80  return x == T (0);
81 }
82 
83 extern OCTAVE_API bool too_large_for_float (double x);
84 
85 extern OCTAVE_API bool too_large_for_float (const Complex& x);
86 
87 extern OCTAVE_API bool is_int_or_inf_or_nan (float x);
88 extern OCTAVE_API bool too_large_for_float (float x);
89 
90 extern OCTAVE_API char * strsave (const char *);
91 
92 extern OCTAVE_API std::string fgets (std::FILE *);
93 extern OCTAVE_API std::string fgetl (std::FILE *);
94 
95 extern OCTAVE_API std::string fgets (std::FILE *, bool& eof);
96 extern OCTAVE_API std::string fgetl (std::FILE *, bool& eof);
97 
98 template <typename T> OCTAVE_API T read_value (std::istream& is);
99 
100 template <> OCTAVE_API double read_value (std::istream& is);
101 template <> OCTAVE_API Complex read_value (std::istream& is);
102 template <> OCTAVE_API float read_value (std::istream& is);
103 template <> OCTAVE_API FloatComplex read_value (std::istream& is);
104 
105 template <typename T> OCTAVE_API void write_value (std::ostream& os, const T& value);
106 
107 template <> OCTAVE_API void write_value (std::ostream& os, const double& value);
108 template <> OCTAVE_API void write_value (std::ostream& os, const Complex& value);
109 template <> OCTAVE_API void write_value (std::ostream& os, const float& value);
110 template <> OCTAVE_API void write_value (std::ostream& os, const FloatComplex& value);
111 
113 
114 extern OCTAVE_API bool int_multiply_overflow (int a, int b, int *r);
115 
116 extern OCTAVE_API bool
117 int_multiply_overflow (long int a, long int b, long int *r);
118 
119 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
120 extern OCTAVE_API bool
121 int_multiply_overflow (long long int a, long long int b, long long int *r);
122 #endif
123 
124 extern OCTAVE_API bool
125 int_multiply_overflow (unsigned int a, unsigned int b, unsigned int *r);
126 
127 extern OCTAVE_API bool
128 int_multiply_overflow (unsigned long int a, unsigned long int b,
129  unsigned long int *r);
130 
131 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
132 extern OCTAVE_API bool
133 int_multiply_overflow (unsigned long long int a, unsigned long long int b,
134  unsigned long long int *r);
135 #endif
136 
137 OCTAVE_END_NAMESPACE(math)
138 OCTAVE_END_NAMESPACE(octave)
139 
140 #endif
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE * x
std::string fgets(std::FILE *)
void write_value(std::ostream &os, const T &value)
Definition: lo-utils.cc:416
bool is_one_or_zero(const T &x)
Definition: lo-utils.h:72
bool int_multiply_overflow(int a, int b, int *r)
Definition: lo-utils.cc:499
char * strsave(const char *)
Definition: lo-utils.cc:78
bool is_zero(const T &x)
Definition: lo-utils.h:78
std::string fgetl(std::FILE *)
bool too_large_for_float(double x)
Definition: lo-utils.cc:56
bool is_int_or_inf_or_nan(float x)
Definition: lo-utils.cc:70
bool xis_int_or_inf_or_nan(double x)
bool any_all_test(F fcn, const T *m, octave_idx_type len)
Definition: lo-utils.h:45
T read_value(std::istream &is)
Definition: lo-utils.cc:191
#define OCTAVE_API
Definition: main.cc:55
T octave_idx_type m
Definition: mx-inlines.cc:781
T * r
Definition: mx-inlines.cc:781
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