GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
lo-utils.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 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
43template <typename F, typename T, bool zero>
44bool
45any_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
69extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
70
71template <typename T>
72bool is_one_or_zero (const T& x)
73{
74 return x == T (0) || x == T (1);
75}
76
77template <typename T>
78bool is_zero (const T& x)
79{
80 return x == T (0);
81}
82
83extern OCTAVE_API bool too_large_for_float (double x);
84
85extern OCTAVE_API bool too_large_for_float (const Complex& x);
86
87extern OCTAVE_API bool is_int_or_inf_or_nan (float x);
88extern OCTAVE_API bool too_large_for_float (float x);
89
90extern OCTAVE_API char * strsave (const char *);
91
92extern OCTAVE_API std::string fgets (std::FILE *);
93extern OCTAVE_API std::string fgetl (std::FILE *);
94
95extern OCTAVE_API std::string fgets (std::FILE *, bool& eof);
96extern OCTAVE_API std::string fgetl (std::FILE *, bool& eof);
97
98template <typename T> OCTAVE_API T read_value (std::istream& is);
99
100template <> OCTAVE_API double read_value (std::istream& is);
101template <> OCTAVE_API Complex read_value (std::istream& is);
102template <> OCTAVE_API float read_value (std::istream& is);
103template <> OCTAVE_API FloatComplex read_value (std::istream& is);
104
105template <typename T> OCTAVE_API void write_value (std::ostream& os, const T& value);
106
107template <> OCTAVE_API void write_value (std::ostream& os, const double& value);
108template <> OCTAVE_API void write_value (std::ostream& os, const Complex& value);
109template <> OCTAVE_API void write_value (std::ostream& os, const float& value);
110template <> OCTAVE_API void write_value (std::ostream& os, const FloatComplex& value);
111
113
114extern OCTAVE_API bool int_multiply_overflow (int a, int b, int *r);
115
116extern OCTAVE_API bool
117int_multiply_overflow (long int a, long int b, long int *r);
118
119#if defined (OCTAVE_HAVE_LONG_LONG_INT)
120extern OCTAVE_API bool
121int_multiply_overflow (long long int a, long long int b, long long int *r);
122#endif
123
124extern OCTAVE_API bool
125int_multiply_overflow (unsigned int a, unsigned int b, unsigned int *r);
126
127extern OCTAVE_API bool
128int_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)
132extern OCTAVE_API bool
133int_multiply_overflow (unsigned long long int a, unsigned long long int b,
134 unsigned long long int *r);
135#endif
136
137OCTAVE_END_NAMESPACE(math)
138OCTAVE_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:412
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:495
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
char * strsave(const char *)
Definition lo-utils.cc:78
T read_value(std::istream &is)
Definition lo-utils.cc:191
#define OCTAVE_API
Definition main.in.cc:55
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