# HG changeset patch # User Jacob Dawid # Date 1338495685 -7200 # Node ID b44ae6c1484a27d9cf469daf123fd4184b0feb5d # Parent 674740c44c09bbb7c3fa76ce60aa75c51a3334d8# Parent 52c5fb67fa5f2f0f14e4eabfc7f8fd3a1a237a56 maint: periodic merge of default to gui diff -r 674740c44c09 -r b44ae6c1484a .hgtags --- a/.hgtags Thu May 31 22:19:53 2012 +0200 +++ b/.hgtags Thu May 31 22:21:25 2012 +0200 @@ -66,3 +66,4 @@ 704f7895eef03008dd79848eb9da4bfb40787d73 release-3-6-0 f947d2922febf12dcd1fb6e21b356756ecb54e55 rc-3-6-2-0 4460c4fb20e6a5d3b1972fa737d4e00eb921545a rc-3-6-2-2 +551566201318bf615b27c60ccf9368f4844008bd release-3-6-2 diff -r 674740c44c09 -r b44ae6c1484a configure.ac diff -r 674740c44c09 -r b44ae6c1484a src/DLD-FUNCTIONS/rand.cc --- a/src/DLD-FUNCTIONS/rand.cc Thu May 31 22:19:53 2012 +0200 +++ b/src/DLD-FUNCTIONS/rand.cc Thu May 31 22:21:25 2012 +0200 @@ -1164,14 +1164,19 @@ octave_idx_type k = i + gnulib::floor (rvec[i] * (n - i)); - if (map.find(k) == map.end()) + //For shuffling first m entries, no need to use extra + //storage + if (k < m) { - map[k] = ivec[i]; - ivec[i] = k; + std::swap (ivec[i], ivec[k]); } else - std::swap (ivec[i], map[k]); + { + if (map.find (k) == map.end ()) + map[k] = k; + std::swap (ivec[i], map[k]); + } } } else @@ -1206,4 +1211,11 @@ /* %!assert (sort (randperm (20)), 1:20) %!assert (length (randperm (20,10)), 10) + +%!test +%! rand ("seed", 0); +%! for i = 1:100 +%! p = randperm (305, 30); +%! assert (length (unique (p)), 30); +%! endfor */ diff -r 674740c44c09 -r b44ae6c1484a src/DLD-FUNCTIONS/str2double.cc --- a/src/DLD-FUNCTIONS/str2double.cc Thu May 31 22:19:53 2012 +0200 +++ b/src/DLD-FUNCTIONS/str2double.cc Thu May 31 22:21:25 2012 +0200 @@ -54,15 +54,15 @@ c = is.peek (); } - if (c == 'I') + if (std::toupper (c) == 'I') { // It's infinity. is.get (); char c1 = is.get (), c2 = is.get (); - if (c1 == 'n' && c2 == 'f') + if (std::tolower (c1) == 'n' && std::tolower (c2) == 'f') { num = octave_Inf; - is.peek (); // May sets EOF bit. + is.peek (); // May set EOF bit. } else is.setstate (std::ios::failbit); // indicate that read has failed. @@ -127,13 +127,37 @@ c = is.peek (); } - // It's i*num or just i. - if (is_imag_unit (c)) + // Imaginary number (i*num or just i), or maybe 'inf'. + if (c == 'i') { - imag = true; + // possible infinity. is.get (); c = is.peek (); + if (is.eof ()) + { + // just 'i' and string is finished. Return immediately. + imag = true; + num = 1.0; + if (negative) + num = -num; + return is; + } + else + { + if (std::tolower (c) != 'n') + imag = true; + is.unget (); + } + } + else if (c == 'j') + imag = true; + + // It's i*num or just i + if (imag) + { + is.get (); + c = is.peek (); // Skip spaces after imaginary unit. while (isspace (c)) { @@ -369,8 +393,10 @@ %!assert (str2double ("NaN"), NaN) %!assert (str2double ("NA"), NA) %!assert (str2double ("Inf"), Inf) +%!assert (str2double ("iNF"), Inf) %!assert (str2double ("-Inf"), -Inf) %!assert (str2double ("Inf*i"), complex (0, Inf)) +%!assert (str2double ("iNF*i"), complex (0, Inf)) %!assert (str2double ("NaN + Inf*i"), complex (NaN, Inf)) %!assert (str2double ("Inf - Inf*i"), complex (Inf, -Inf)) %!assert (str2double ("-i*NaN - Inf"), complex (-Inf, -NaN))