# HG changeset patch # User John W. Eaton # Date 1340742313 14400 # Node ID 616981c9907c28101f0dd7619ff9cd0c757eae91 # Parent d5aee269b770c2b2fb2ff4c1c903fd1bbc049de3# Parent 980e2d5c83f75208d64f150b657ed32a3a5a807a maint: periodic merge of stable to default diff -r d5aee269b770 -r 616981c9907c doc/interpreter/oop.txi --- a/doc/interpreter/oop.txi Mon Jun 25 22:25:56 2012 +0200 +++ b/doc/interpreter/oop.txi Tue Jun 26 16:25:13 2012 -0400 @@ -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 diff -r d5aee269b770 -r 616981c9907c liboctave/lo-utils.cc --- a/liboctave/lo-utils.cc Mon Jun 25 22:25:56 2012 +0200 +++ b/liboctave/lo-utils.cc Tue Jun 26 16:25:13 2012 -0400 @@ -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;