comparison liboctave/lo-utils.cc @ 6194:0d2ff0dfb159

[project @ 2006-12-01 05:25:38 by jwe]
author jwe
date Fri, 01 Dec 2006 05:25:38 +0000
parents ace8d8d26933
children e5ed0d1edddc
comparison
equal deleted inserted replaced
6193:ca97c6b26902 6194:0d2ff0dfb159
208 208
209 return retval; 209 return retval;
210 } 210 }
211 211
212 static inline double 212 static inline double
213 read_inf_nan_na (std::istream& is, char c) 213 read_inf_nan_na (std::istream& is, char c, char sign = '+')
214 { 214 {
215 double d = 0.0; 215 double d = 0.0;
216 216
217 switch (c) 217 switch (c)
218 { 218 {
221 is >> c; 221 is >> c;
222 if (c == 'n' || c == 'N') 222 if (c == 'n' || c == 'N')
223 { 223 {
224 is >> c; 224 is >> c;
225 if (c == 'f' || c == 'F') 225 if (c == 'f' || c == 'F')
226 d = octave_Inf; 226 d = sign == '-' ? -octave_Inf : octave_Inf;
227 else 227 else
228 is.putback (c); 228 is.putback (c);
229 } 229 }
230 else 230 else
231 is.putback (c); 231 is.putback (c);
261 double 261 double
262 octave_read_double (std::istream& is) 262 octave_read_double (std::istream& is)
263 { 263 {
264 double d = 0.0; 264 double d = 0.0;
265 265
266 char c = 0; 266 char c1 = 0;
267 267
268 is >> c; 268 is >> c1;
269 switch (c) 269 switch (c1)
270 { 270 {
271 case '-':
272 {
273 char c2 = 0;
274 is >> c2;
275 if (c2 == 'i' || c2 == 'I')
276 d = read_inf_nan_na (is, c2, c1);
277 else
278 {
279 is.putback (c2);
280 is.putback (c1);
281 }
282 }
283 break;
284
285 case '+':
286 {
287 char c2 = 0;
288 is >> c2;
289 if (c2 == 'i' || c2 == 'I')
290 d = read_inf_nan_na (is, c2, c1);
291 else
292 {
293 is.putback (c2);
294 is.putback (c1);
295 }
296 }
297 break;
298
271 case 'i': case 'I': 299 case 'i': case 'I':
272 case 'n': case 'N': 300 case 'n': case 'N':
273 d = read_inf_nan_na (is, c); 301 d = read_inf_nan_na (is, c1);
274 break; 302 break;
275 303
276 default: 304 default:
277 is.putback (c); 305 is.putback (c1);
278 is >> d; 306 is >> d;
279 } 307 }
280 308
281 return d; 309 return d;
282 } 310 }