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