GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lo-utils.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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 "quit.h"
34 
35 #include "lo-cutils.h"
36 #include "oct-cmplx.h"
37 
38 // Generic any/all test functionality with arbitrary predicate.
39 
40 template <typename F, typename T, bool zero>
41 bool
43 {
45 
46  for (i = 0; i < len - 3; i += 4)
47  {
48  octave_quit ();
49 
50  if (fcn (m[i]) != zero
51  || fcn (m[i+1]) != zero
52  || fcn (m[i+2]) != zero
53  || fcn (m[i+3]) != zero)
54  return ! zero;
55  }
56 
57  octave_quit ();
58 
59  for (; i < len; i++)
60  if (fcn (m[i]) != zero)
61  return ! zero;
62 
63  return zero;
64 }
65 
66 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
67 extern OCTAVE_API bool xis_one_or_zero (double x);
68 extern OCTAVE_API bool xis_zero (double x);
69 extern OCTAVE_API bool xtoo_large_for_float (double x);
70 
71 extern OCTAVE_API bool xtoo_large_for_float (const Complex& x);
72 
73 extern OCTAVE_API bool xis_int_or_inf_or_nan (float x);
74 extern OCTAVE_API bool xis_one_or_zero (float x);
75 extern OCTAVE_API bool xis_zero (float x);
76 extern OCTAVE_API bool xtoo_large_for_float (float x);
77 
78 extern OCTAVE_API char *strsave (const char *);
79 
80 extern OCTAVE_API void
81 octave_putenv (const std::string&, const std::string&);
82 
83 extern OCTAVE_API std::string octave_fgets (std::FILE *);
84 extern OCTAVE_API std::string octave_fgetl (std::FILE *);
85 
86 extern OCTAVE_API std::string octave_fgets (std::FILE *, bool& eof);
87 extern OCTAVE_API std::string octave_fgetl (std::FILE *, bool& eof);
88 
89 template <typename T>
90 T
91 octave_read_value (std::istream& is)
92 {
93  T retval;
94  is >> retval;
95  return retval;
96 }
97 
98 template <> OCTAVE_API double octave_read_value (std::istream& is);
99 template <> OCTAVE_API Complex octave_read_value (std::istream& is);
100 template <> OCTAVE_API float octave_read_value (std::istream& is);
101 template <> OCTAVE_API FloatComplex octave_read_value (std::istream& is);
102 
103 // The next four functions are provided for backward compatibility.
104 inline double
105 octave_read_double (std::istream& is)
106 {
107  return octave_read_value<double> (is);
108 }
109 
110 inline Complex
111 octave_read_complex (std::istream& is)
112 {
113  return octave_read_value<Complex> (is);
114 }
115 
116 inline float
117 octave_read_float (std::istream& is)
118 {
119  return octave_read_value<float> (is);
120 }
121 
122 inline FloatComplex
124 {
125  return octave_read_value<FloatComplex> (is);
126 }
127 
128 extern OCTAVE_API void
129 octave_write_double (std::ostream& os, double dval);
130 
131 extern OCTAVE_API void
132 octave_write_complex (std::ostream& os, const Complex& cval);
133 
134 extern OCTAVE_API void
135 octave_write_float (std::ostream& os, float dval);
136 
137 extern OCTAVE_API void
138 octave_write_float_complex (std::ostream& os, const FloatComplex& cval);
139 
140 #endif
OCTAVE_API void octave_write_float(std::ostream &os, float dval)
Definition: lo-utils.cc:411
double octave_read_double(std::istream &is)
Definition: lo-utils.h:105
bool any_all_test(F fcn, const T *m, octave_idx_type len)
Definition: lo-utils.h:42
OCTAVE_API void octave_write_double(std::ostream &os, double dval)
Definition: lo-utils.cc:388
is greater than zero
Definition: load-path.cc:2339
OCTAVE_API std::string octave_fgetl(std::FILE *)
octave_function * fcn
Definition: ov-class.cc:1743
Complex octave_read_complex(std::istream &is)
Definition: lo-utils.h:111
OCTAVE_API bool xis_one_or_zero(double x)
Definition: lo-utils.cc:48
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
OCTAVE_API void octave_write_float_complex(std::ostream &os, const FloatComplex &cval)
Definition: lo-utils.cc:424
octave_value retval
Definition: data.cc:6294
OCTAVE_API char * strsave(const char *)
Definition: lo-utils.cc:78
OCTAVE_API bool xis_zero(double x)
Definition: lo-utils.cc:51
OCTAVE_API void octave_putenv(const std::string &, const std::string &)
Definition: lo-utils.cc:95
OCTAVE_API bool xis_int_or_inf_or_nan(double x)
Definition: lo-utils.cc:45
OCTAVE_API void octave_write_complex(std::ostream &os, const Complex &cval)
Definition: lo-utils.cc:401
FloatComplex octave_read_float_complex(std::istream &is)
Definition: lo-utils.h:123
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
T octave_read_value(std::istream &is)
Definition: lo-utils.h:91
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:54
write the output to stdout if nargout is
Definition: load-save.cc:1576
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:854
float octave_read_float(std::istream &is)
Definition: lo-utils.h:117
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &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:719