Mercurial > hg > octave-lyh
changeset 14807:616981c9907c
maint: periodic merge of stable to default
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 26 Jun 2012 16:25:13 -0400 |
parents | d5aee269b770 (current diff) 980e2d5c83f7 (diff) |
children | 2e2a336c6b48 |
files | |
diffstat | 2 files changed, 60 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/oop.txi +++ b/doc/interpreter/oop.txi @@ -549,7 +549,7 @@ & $a >= b$ && ge (a, b) && Greater than or equal to operator&\cr & $a == b$ && eq (a, b) && Equal to operator&\cr & $a != b$ && ne (a, b) && Not equal to operator&\cr -& $a \& b$ && and (a, b) && Logical and operator&\cr +& $a & b$ && and (a, b) && Logical and operator&\cr & $a | b$ && or (a, b) && Logical or operator&\cr & $! b$ && not (a) && Logical not operator&\cr & $a'$ && ctranspose (a) && Complex conjugate transpose operator &\cr
--- a/liboctave/lo-utils.cc +++ b/liboctave/lo-utils.cc @@ -195,8 +195,11 @@ return retval; } +// Note that the caller is responsible for repositioning the stream on +// failure. + static inline double -read_inf_nan_na (std::istream& is, char c0, char sign = '+') +read_inf_nan_na (std::istream& is, char c0) { double d = 0.0; @@ -209,21 +212,12 @@ { char c2 = is.get (); if (c2 == 'f' || c2 == 'F') - d = sign == '-' ? -octave_Inf : octave_Inf; + d = octave_Inf; else - { - is.putback (c2); - is.putback (c1); - is.putback (c0); - is.setstate (std::ios::failbit); - } + is.setstate (std::ios::failbit); } else - { - is.putback (c1); - is.putback (c0); - is.setstate (std::ios::failbit); - } + is.setstate (std::ios::failbit); } break; @@ -236,17 +230,10 @@ if (c2 == 'n' || c2 == 'N') d = octave_NaN; else - { - is.putback (c2); - d = octave_NA; - } + d = octave_NA; } else - { - is.putback (c1); - is.putback (c0); - is.setstate (std::ios::failbit); - } + is.setstate (std::ios::failbit); } break; @@ -265,40 +252,37 @@ { double d = 0.0; + // FIXME -- resetting stream position is likely to fail unless we are + // reading from a file. + std::ios::streampos pos = is.tellg (); + char c1 = ' '; while (isspace (c1)) c1 = is.get (); + bool neg = false; + switch (c1) { case '-': - { - char c2 = 0; - c2 = is.get (); - if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') - d = read_inf_nan_na (is, c2, c1); - else - { - is.putback (c2); - is.putback (c1); - is >> d; - } - } - break; + neg = true; + // fall through... case '+': { char c2 = 0; c2 = is.get (); if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') - d = read_inf_nan_na (is, c2, c1); + d = read_inf_nan_na (is, c2); else { is.putback (c2); - is.putback (c1); is >> d; } + + if (neg && ! is.fail ()) + d = -d; } break; @@ -310,6 +294,15 @@ default: is.putback (c1); is >> d; + break; + } + + std::ios::iostate status = is.rdstate (); + if (status & std::ios::failbit) + { + is.clear (); + is.seekg (pos); + is.setstate (status); } return d; @@ -358,6 +351,9 @@ } +// Note that the caller is responsible for repositioning the stream on +// failure. + static inline float read_float_inf_nan_na (std::istream& is, char c0, char sign = '+') { @@ -372,21 +368,12 @@ { char c2 = is.get (); if (c2 == 'f' || c2 == 'F') - d = sign == '-' ? -octave_Float_Inf : octave_Float_Inf; + d = octave_Float_Inf; else - { - is.putback (c2); - is.putback (c1); - is.putback (c0); - is.setstate (std::ios::failbit); - } + is.setstate (std::ios::failbit); } else - { - is.putback (c1); - is.putback (c0); - is.setstate (std::ios::failbit); - } + is.setstate (std::ios::failbit); } break; @@ -399,17 +386,10 @@ if (c2 == 'n' || c2 == 'N') d = octave_Float_NaN; else - { - is.putback (c2); - d = octave_Float_NA; - } + d = octave_Float_NA; } else - { - is.putback (c1); - is.putback (c0); - is.setstate (std::ios::failbit); - } + is.setstate (std::ios::failbit); } break; @@ -428,40 +408,37 @@ { float d = 0.0; + // FIXME -- resetting stream position is likely to fail unless we are + // reading from a file. + std::ios::streampos pos = is.tellg (); + char c1 = ' '; while (isspace (c1)) c1 = is.get (); + bool neg = false; + switch (c1) { case '-': - { - char c2 = 0; - c2 = is.get (); - if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') - d = read_float_inf_nan_na (is, c2, c1); - else - { - is.putback (c2); - is.putback (c1); - is >> d; - } - } - break; + neg = true; + // fall through... case '+': { char c2 = 0; c2 = is.get (); if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') - d = read_float_inf_nan_na (is, c2, c1); + d = read_float_inf_nan_na (is, c2); else { is.putback (c2); - is.putback (c1); is >> d; } + + if (neg && ! is.fail ()) + d = -d; } break; @@ -473,6 +450,15 @@ default: is.putback (c1); is >> d; + break; + } + + std::ios::iostate status = is.rdstate (); + if (status & std::ios::failbit) + { + is.clear (); + is.seekg (pos); + is.setstate (status); } return d;