Mercurial > hg > octave-lyh
annotate liboctave/lo-utils.cc @ 14507:3f21c0c34b8f
check for function/file name mismatch when parsing class methods
* oct-parse.yy (frob_function): Also check for and repair function
name/file name mismatch when parsing class methods.
* test/bug-36025: New test directory.
* test/Makefile.am: Include bug-36025/module.mk.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 28 Mar 2012 23:21:44 -0400 |
parents | 72c96de7a403 |
children | 980e2d5c83f7 |
rev | line source |
---|---|
1993 | 1 // utils.cc |
1967 | 2 /* |
3 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12995
diff
changeset
|
4 Copyright (C) 1996-2012 John W. Eaton |
1967 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1967 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1967 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
6907 | 28 #include <cctype> |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
29 #include <cstdlib> |
2926 | 30 #include <cstdio> |
7048 | 31 #include <cstring> |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
32 #include <cfloat> |
1967 | 33 |
6490 | 34 #include <limits> |
2926 | 35 #include <string> |
36 | |
37 #include <sys/types.h> | |
38 #include <unistd.h> | |
39 | |
10068
ca93f583573d
handle interrupts octave_fgets
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
40 #include "quit.h" |
ca93f583573d
handle interrupts octave_fgets
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
41 |
2926 | 42 #include "lo-error.h" |
4130 | 43 #include "lo-ieee.h" |
1967 | 44 #include "lo-mappers.h" |
45 #include "lo-utils.h" | |
46 | |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
47 bool xis_int_or_inf_or_nan (double x) |
11013
63f79f798a14
fix small typos in new tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11010
diff
changeset
|
48 { return xisnan (x) || D_NINT (x) == x; } |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
49 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
50 bool xis_one_or_zero (double x) |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
51 { return x == 0 || x == 1; } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
52 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
53 bool xis_zero (double x) |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
54 { return x == 0; } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
55 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
56 bool xtoo_large_for_float (double x) |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
57 { return (! (xisnan (x) || xisinf (x)) && fabs (x) > FLT_MAX); } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
58 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
59 bool xis_int_or_inf_or_nan (float x) |
11013
63f79f798a14
fix small typos in new tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11010
diff
changeset
|
60 { return xisnan (x) || D_NINT (x) == x; } |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
61 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
62 bool xis_one_or_zero (float x) |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
63 { return x == 0 || x == 1; } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
64 |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
65 bool xis_zero (float x) |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
66 { return x == 0; } |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10463
diff
changeset
|
67 |
2926 | 68 // Save a string. |
69 | |
70 char * | |
71 strsave (const char *s) | |
72 { | |
73 if (! s) | |
74 return 0; | |
75 | |
76 int len = strlen (s); | |
77 char *tmp = new char [len+1]; | |
78 tmp = strcpy (tmp, s); | |
79 return tmp; | |
80 } | |
81 | |
82 // This function was adapted from xputenv from Karl Berry's kpathsearch | |
83 // library. | |
84 | |
5775 | 85 // FIXME -- make this do the right thing if we don't have a |
2926 | 86 // SMART_PUTENV. |
87 | |
88 void | |
3504 | 89 octave_putenv (const std::string& name, const std::string& value) |
2926 | 90 { |
91 int new_len = name.length () + value.length () + 2; | |
92 | |
10411 | 93 char *new_item = static_cast<char*> (gnulib::malloc (new_len)); |
2926 | 94 |
95 sprintf (new_item, "%s=%s", name.c_str (), value.c_str ()); | |
96 | |
97 // As far as I can see there's no way to distinguish between the | |
98 // various errors; putenv doesn't have errno values. | |
99 | |
100 if (putenv (new_item) < 0) | |
101 (*current_liboctave_error_handler) ("putenv (%s) failed", new_item); | |
102 } | |
103 | |
3504 | 104 std::string |
2926 | 105 octave_fgets (FILE *f) |
106 { | |
4527 | 107 bool eof; |
108 return octave_fgets (f, eof); | |
109 } | |
110 | |
111 std::string | |
112 octave_fgets (FILE *f, bool& eof) | |
113 { | |
114 eof = false; | |
115 | |
3504 | 116 std::string retval; |
2926 | 117 |
118 int grow_size = 1024; | |
119 int max_size = grow_size; | |
120 | |
10411 | 121 char *buf = static_cast<char *> (gnulib::malloc (max_size)); |
2926 | 122 char *bufptr = buf; |
123 int len = 0; | |
124 | |
125 do | |
126 { | |
12918
f3a8d1efe2c1
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
127 if (gnulib::fgets (bufptr, grow_size, f)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
128 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
129 len = strlen (bufptr); |
2926 | 130 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
131 if (len == grow_size - 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
132 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
133 int tmp = bufptr - buf + grow_size - 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
134 grow_size *= 2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
135 max_size += grow_size; |
10411 | 136 buf = static_cast<char *> (gnulib::realloc (buf, max_size)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
137 bufptr = buf + tmp; |
2926 | 138 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
139 if (*(bufptr-1) == '\n') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
140 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
141 *bufptr = '\0'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
142 retval = buf; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
143 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
144 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
145 else if (bufptr[len-1] != '\n') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
146 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
147 bufptr[len++] = '\n'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
148 bufptr[len] = '\0'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
149 retval = buf; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
150 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
151 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
152 retval = buf; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
153 } |
2926 | 154 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
155 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
156 if (len == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
157 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
158 eof = true; |
4527 | 159 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
160 free (buf); |
2926 | 161 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
162 buf = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
163 } |
2926 | 164 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
165 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
166 } |
2926 | 167 } |
168 while (retval.empty ()); | |
169 | |
170 if (buf) | |
171 free (buf); | |
172 | |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10068
diff
changeset
|
173 octave_quit (); |
10068
ca93f583573d
handle interrupts octave_fgets
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
174 |
2926 | 175 return retval; |
176 } | |
177 | |
3970 | 178 std::string |
179 octave_fgetl (FILE *f) | |
180 { | |
4527 | 181 bool eof; |
182 return octave_fgetl (f, eof); | |
183 } | |
184 | |
185 std::string | |
186 octave_fgetl (FILE *f, bool& eof) | |
187 { | |
188 std::string retval = octave_fgets (f, eof); | |
3970 | 189 |
190 size_t len = retval.length (); | |
191 | |
192 if (retval[len-1] == '\n') | |
193 retval.resize (len-1); | |
194 | |
195 return retval; | |
196 } | |
197 | |
4130 | 198 static inline double |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
199 read_inf_nan_na (std::istream& is, char c0, char sign = '+') |
4130 | 200 { |
201 double d = 0.0; | |
202 | |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
203 switch (c0) |
4130 | 204 { |
205 case 'i': case 'I': | |
206 { | |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
207 char c1 = is.get (); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
208 if (c1 == 'n' || c1 == 'N') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
209 { |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
210 char c2 = is.get (); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
211 if (c2 == 'f' || c2 == 'F') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
212 d = sign == '-' ? -octave_Inf : octave_Inf; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
213 else |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
214 { |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
215 is.putback (c2); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
216 is.putback (c1); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
217 is.putback (c0); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
218 is.setstate (std::ios::failbit); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
219 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
220 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
221 else |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
222 { |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
223 is.putback (c1); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
224 is.putback (c0); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
225 is.setstate (std::ios::failbit); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
226 } |
4130 | 227 } |
228 break; | |
229 | |
230 case 'n': case 'N': | |
231 { | |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
232 char c1 = is.get (); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
233 if (c1 == 'a' || c1 == 'A') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
234 { |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
235 char c2 = is.get (); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
236 if (c2 == 'n' || c2 == 'N') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
237 d = octave_NaN; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
238 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
239 { |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
240 is.putback (c2); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
241 d = octave_NA; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
242 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
243 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
244 else |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
245 { |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
246 is.putback (c1); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
247 is.putback (c0); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
248 is.setstate (std::ios::failbit); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
249 } |
4130 | 250 } |
251 break; | |
252 | |
253 default: | |
254 abort (); | |
255 } | |
256 | |
257 return d; | |
258 } | |
259 | |
12936
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
12918
diff
changeset
|
260 // Read a double value. Discard any sign on NaN and NA. |
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
12918
diff
changeset
|
261 |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
262 template <> |
4130 | 263 double |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
264 octave_read_value (std::istream& is) |
4130 | 265 { |
266 double d = 0.0; | |
267 | |
6907 | 268 char c1 = ' '; |
4130 | 269 |
6907 | 270 while (isspace (c1)) |
271 c1 = is.get (); | |
272 | |
6194 | 273 switch (c1) |
4130 | 274 { |
6194 | 275 case '-': |
276 { | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
277 char c2 = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
278 c2 = is.get (); |
12936
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
12918
diff
changeset
|
279 if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
280 d = read_inf_nan_na (is, c2, c1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
281 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
282 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
283 is.putback (c2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
284 is.putback (c1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
285 is >> d; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
286 } |
6194 | 287 } |
288 break; | |
289 | |
290 case '+': | |
291 { | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
292 char c2 = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
293 c2 = is.get (); |
12936
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
12918
diff
changeset
|
294 if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
295 d = read_inf_nan_na (is, c2, c1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
296 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
297 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
298 is.putback (c2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
299 is.putback (c1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
300 is >> d; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
301 } |
6194 | 302 } |
303 break; | |
304 | |
4130 | 305 case 'i': case 'I': |
306 case 'n': case 'N': | |
6194 | 307 d = read_inf_nan_na (is, c1); |
4130 | 308 break; |
309 | |
310 default: | |
6194 | 311 is.putback (c1); |
4130 | 312 is >> d; |
313 } | |
314 | |
315 return d; | |
316 } | |
317 | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
318 template <> |
4130 | 319 Complex |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
320 octave_read_value (std::istream& is) |
4130 | 321 { |
322 double re = 0.0, im = 0.0; | |
323 | |
324 Complex cx = 0.0; | |
325 | |
6907 | 326 char ch = ' '; |
4130 | 327 |
6907 | 328 while (isspace (ch)) |
329 ch = is.get (); | |
4130 | 330 |
331 if (ch == '(') | |
332 { | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
333 re = octave_read_value<double> (is); |
6897 | 334 ch = is.get (); |
4130 | 335 |
336 if (ch == ',') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
337 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
338 im = octave_read_value<double> (is); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
339 ch = is.get (); |
4130 | 340 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
341 if (ch == ')') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
342 cx = Complex (re, im); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
343 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
344 is.setstate (std::ios::failbit); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
345 } |
4130 | 346 else if (ch == ')') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
347 cx = re; |
4130 | 348 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
349 is.setstate (std::ios::failbit); |
4130 | 350 } |
351 else | |
352 { | |
353 is.putback (ch); | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
354 cx = octave_read_value<double> (is); |
4130 | 355 } |
356 | |
357 return cx; | |
358 | |
359 } | |
360 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
361 static inline float |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
362 read_float_inf_nan_na (std::istream& is, char c0, char sign = '+') |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
363 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
364 float d = 0.0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
365 |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
366 switch (c0) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
367 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
368 case 'i': case 'I': |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
369 { |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
370 char c1 = is.get (); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
371 if (c1 == 'n' || c1 == 'N') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
372 { |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
373 char c2 = is.get (); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
374 if (c2 == 'f' || c2 == 'F') |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
375 d = sign == '-' ? -octave_Float_Inf : octave_Float_Inf; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
376 else |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
377 { |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
378 is.putback (c2); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
379 is.putback (c1); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
380 is.putback (c0); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
381 is.setstate (std::ios::failbit); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
382 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
383 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
384 else |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
385 { |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
386 is.putback (c1); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
387 is.putback (c0); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
388 is.setstate (std::ios::failbit); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
389 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
390 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
391 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
392 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
393 case 'n': case 'N': |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
394 { |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
395 char c1 = is.get (); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
396 if (c1 == 'a' || c1 == 'A') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
397 { |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
398 char c2 = is.get (); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
399 if (c2 == 'n' || c2 == 'N') |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
400 d = octave_Float_NaN; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
401 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
402 { |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
403 is.putback (c2); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
404 d = octave_Float_NA; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
405 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
406 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
407 else |
12995
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
408 { |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
409 is.putback (c1); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
410 is.putback (c0); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
411 is.setstate (std::ios::failbit); |
7872afb42fab
fix scanf problem with reading I (bug #33722)
John W. Eaton <jwe@octave.org>
parents:
12936
diff
changeset
|
412 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
413 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
414 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
415 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
416 default: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
417 abort (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
418 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
419 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
420 return d; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
421 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
422 |
12936
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
12918
diff
changeset
|
423 // Read a float value. Discard any sign on NaN and NA. |
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
12918
diff
changeset
|
424 |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
425 template <> |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
426 float |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
427 octave_read_value (std::istream& is) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
428 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
429 float d = 0.0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
430 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
431 char c1 = ' '; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
432 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
433 while (isspace (c1)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
434 c1 = is.get (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
435 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
436 switch (c1) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
437 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
438 case '-': |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
439 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
440 char c2 = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
441 c2 = is.get (); |
12936
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
12918
diff
changeset
|
442 if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
443 d = read_float_inf_nan_na (is, c2, c1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
444 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
445 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
446 is.putback (c2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
447 is.putback (c1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
448 is >> d; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
449 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
450 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
451 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
452 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
453 case '+': |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
454 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
455 char c2 = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
456 c2 = is.get (); |
12936
b74cb659e757
accept but discard sign when reading NA and NaN values
John W. Eaton <jwe@octave.org>
parents:
12918
diff
changeset
|
457 if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
458 d = read_float_inf_nan_na (is, c2, c1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
459 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
460 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
461 is.putback (c2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
462 is.putback (c1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
463 is >> d; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
464 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
465 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
466 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
467 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
468 case 'i': case 'I': |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
469 case 'n': case 'N': |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
470 d = read_float_inf_nan_na (is, c1); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
471 break; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
472 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
473 default: |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
474 is.putback (c1); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
475 is >> d; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
476 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
477 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
478 return d; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
479 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
480 |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
481 template <> |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
482 FloatComplex |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
483 octave_read_value (std::istream& is) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
484 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
485 float re = 0.0, im = 0.0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
486 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
487 FloatComplex cx = 0.0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
488 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
489 char ch = ' '; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
490 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
491 while (isspace (ch)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
492 ch = is.get (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
493 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
494 if (ch == '(') |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
495 { |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
496 re = octave_read_value<float> (is); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
497 ch = is.get (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
498 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
499 if (ch == ',') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
500 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
501 im = octave_read_value<float> (is); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
502 ch = is.get (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
503 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
504 if (ch == ')') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
505 cx = FloatComplex (re, im); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
506 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
507 is.setstate (std::ios::failbit); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
508 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
509 else if (ch == ')') |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
510 cx = re; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
511 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
512 is.setstate (std::ios::failbit); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
513 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
514 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
515 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
516 is.putback (ch); |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
517 cx = octave_read_value<float> (is); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
518 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
519 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
520 return cx; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
521 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
522 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
523 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
524 void |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
525 octave_write_double (std::ostream& os, double d) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
526 { |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
527 if (lo_ieee_is_NA (d)) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
528 os << "NA"; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
529 else if (lo_ieee_isnan (d)) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
530 os << "NaN"; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
531 else if (lo_ieee_isinf (d)) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
532 os << (d < 0 ? "-Inf" : "Inf"); |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
533 else |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
534 os << d; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
535 } |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
536 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
537 void |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
538 octave_write_complex (std::ostream& os, const Complex& c) |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
539 { |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
540 os << "("; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
541 octave_write_double (os, real (c)); |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
542 os << ","; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
543 octave_write_double (os, imag (c)); |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
544 os << ")"; |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
545 } |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
546 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
547 void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
548 octave_write_float (std::ostream& os, float d) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
549 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
550 if (lo_ieee_is_NA (d)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
551 os << "NA"; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
552 else if (lo_ieee_isnan (d)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
553 os << "NaN"; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
554 else if (lo_ieee_isinf (d)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
555 os << (d < 0 ? "-Inf" : "Inf"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
556 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
557 os << d; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
558 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
559 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
560 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
561 octave_write_float_complex (std::ostream& os, const FloatComplex& c) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
562 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
563 os << "("; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
564 octave_write_float (os, real (c)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
565 os << ","; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
566 octave_write_float (os, imag (c)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
567 os << ")"; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
568 } |