annotate liboctave/util/lo-utils.h @ 23220:092078913d54

maint: Merge stable to default.
author John W. Eaton <jwe@octave.org>
date Wed, 22 Feb 2017 12:58:07 -0500
parents ef4d915df748 3ac9f9ecfae5
children 3f1bf237908b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
1 /*
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 1996-2017 John W. Eaton
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
4
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
6
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
10 (at your option) any later version.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
15 GNU General Public License for more details.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
16
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6111
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6111
diff changeset
19 <http://www.gnu.org/licenses/>.
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
20
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
21 */
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
22
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 19697
diff changeset
23 #if ! defined (octave_lo_utils_h)
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17744
diff changeset
24 #define octave_lo_utils_h 1
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
25
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
26 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
27
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
28 #include <cstdio>
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
29
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
30 #include <iostream>
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
31 #include <string>
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
32
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
33 #include "quit.h"
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
34
11512
e4e82740e9cd prototype fixes for C language files
John W. Eaton <jwe@octave.org>
parents: 11211
diff changeset
35 #include "lo-cutils.h"
4130
7d9bda865012 [project @ 2002-10-28 21:05:30 by jwe]
jwe
parents: 3970
diff changeset
36 #include "oct-cmplx.h"
7d9bda865012 [project @ 2002-10-28 21:05:30 by jwe]
jwe
parents: 3970
diff changeset
37
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
38 // Generic any/all test functionality with arbitrary predicate.
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
39
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 20791
diff changeset
40 template <typename F, typename T, bool zero>
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
41 bool
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
42 any_all_test (F fcn, const T *m, octave_idx_type len)
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
43 {
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
44 octave_idx_type i;
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
45
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
46 for (i = 0; i < len - 3; i += 4)
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
47 {
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
48 octave_quit ();
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
49
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
50 if (fcn (m[i]) != zero
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
51 || fcn (m[i+1]) != zero
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
52 || fcn (m[i+2]) != zero
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
53 || fcn (m[i+3]) != zero)
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
54 return ! zero;
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
55 }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
56
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
57 octave_quit ();
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
58
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
59 for (; i < len; i++)
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
60 if (fcn (m[i]) != zero)
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
61 return ! zero;
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
62
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
63 return zero;
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
64 }
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
65
11010
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
66 extern OCTAVE_API bool xis_int_or_inf_or_nan (double x);
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
67 extern OCTAVE_API bool xis_one_or_zero (double x);
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
68 extern OCTAVE_API bool xis_zero (double x);
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
69 extern OCTAVE_API bool xtoo_large_for_float (double x);
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
70
15212
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
71 extern OCTAVE_API bool xtoo_large_for_float (const Complex& x);
4bbd3bbb8912 reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
72
11010
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
73 extern OCTAVE_API bool xis_int_or_inf_or_nan (float x);
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
74 extern OCTAVE_API bool xis_one_or_zero (float x);
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
75 extern OCTAVE_API bool xis_zero (float x);
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
76 extern OCTAVE_API bool xtoo_large_for_float (float x);
9478b216752e simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents: 11006
diff changeset
77
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5453
diff changeset
78 extern OCTAVE_API char *strsave (const char *);
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
79
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
80 extern OCTAVE_API void
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
81 octave_putenv (const std::string&, const std::string&);
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
82
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5453
diff changeset
83 extern OCTAVE_API std::string octave_fgets (std::FILE *);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5453
diff changeset
84 extern OCTAVE_API std::string octave_fgetl (std::FILE *);
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
85
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5453
diff changeset
86 extern OCTAVE_API std::string octave_fgets (std::FILE *, bool& eof);
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5453
diff changeset
87 extern OCTAVE_API std::string octave_fgetl (std::FILE *, bool& eof);
3970
4f884e25aab9 [project @ 2002-07-02 04:14:35 by jwe]
jwe
parents: 3803
diff changeset
88
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
89 template <typename T>
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
90 T
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
91 octave_read_value (std::istream& is)
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
92 {
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
93 T retval;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
94 is >> retval;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
95 return retval;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
96 }
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
97
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
98 template <> OCTAVE_API double octave_read_value (std::istream& is);
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
99 template <> OCTAVE_API Complex octave_read_value (std::istream& is);
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
100 template <> OCTAVE_API float octave_read_value (std::istream& is);
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
101 template <> OCTAVE_API FloatComplex octave_read_value (std::istream& is);
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
102
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
103 // The next four functions are provided for backward compatibility.
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
104 inline double
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
105 octave_read_double (std::istream& is)
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
106 {
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
107 return octave_read_value<double> (is);
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
108 }
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
109
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
110 inline Complex
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
111 octave_read_complex (std::istream& is)
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
112 {
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
113 return octave_read_value<Complex> (is);
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
114 }
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
115
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
116 inline float
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
117 octave_read_float (std::istream& is)
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
118 {
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
119 return octave_read_value<float> (is);
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
120 }
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
121
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
122 inline FloatComplex
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
123 octave_read_float_complex (std::istream& is)
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
124 {
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
125 return octave_read_value<FloatComplex> (is);
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 8950
diff changeset
126 }
4130
7d9bda865012 [project @ 2002-10-28 21:05:30 by jwe]
jwe
parents: 3970
diff changeset
127
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
128 extern OCTAVE_API void
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
129 octave_write_double (std::ostream& os, double dval);
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
130
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
131 extern OCTAVE_API void
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
132 octave_write_complex (std::ostream& os, const Complex& cval);
4130
7d9bda865012 [project @ 2002-10-28 21:05:30 by jwe]
jwe
parents: 3970
diff changeset
133
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
134 extern OCTAVE_API void
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
135 octave_write_float (std::ostream& os, float dval);
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
136
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
137 extern OCTAVE_API void
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
138 octave_write_float_complex (std::ostream& os, const FloatComplex& cval);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
139
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
140 #endif