Mercurial > hg > octave-lyh
changeset 14708:b44ae6c1484a gui
maint: periodic merge of default to gui
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Thu, 31 May 2012 22:21:25 +0200 |
parents | 674740c44c09 (current diff) 52c5fb67fa5f (diff) |
children | f50591409306 |
files | configure.ac |
diffstat | 3 files changed, 49 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags +++ b/.hgtags @@ -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
--- a/src/DLD-FUNCTIONS/rand.cc +++ b/src/DLD-FUNCTIONS/rand.cc @@ -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 */
--- a/src/DLD-FUNCTIONS/str2double.cc +++ b/src/DLD-FUNCTIONS/str2double.cc @@ -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))