Mercurial > octave
diff libinterp/corefcn/rand.cc @ 25651:c759aa39c23a stable
Produce same random number stream for "state" initialized to Inf (bug #54342).
* rand.cc (Frand): Update BIST test for new behavior.
* rand.cc (do_rand): Map Inf values in initialization state vector to 0.0 which
previous versions of Octave used.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 20 Jul 2018 12:26:48 -0700 |
parents | 13fd0610480f |
children | b400ad33d92d 85f499b88c43 |
line wrap: on
line diff
--- a/libinterp/corefcn/rand.cc Thu Jul 19 08:24:16 2018 -0700 +++ b/libinterp/corefcn/rand.cc Fri Jul 20 12:26:48 2018 -0700 @@ -266,7 +266,13 @@ else { ColumnVector s = - ColumnVector (args(idx+1).vector_value(false, true)); + ColumnVector (args(idx+1).vector_value (false, true)); + + // Backwards compatibility with previous versions of + // Octave which mapped Inf to 0. + for (octave_idx_type i = 0; i < s.numel (); i++) + if (octave::math::isinf (s.xelem (i))) + s.xelem (i) = 0.0; octave_rand::state (s, fcn); } @@ -528,7 +534,7 @@ %!assert (__rand_sample__ (-1), __rand_sample__ (0)) %!assert (__rand_sample__ (-Inf), __rand_sample__ (0)) %!assert (__rand_sample__ (2^33), __rand_sample__ (intmax ("uint32"))) -%!assert (__rand_sample__ (Inf), __rand_sample__ (intmax ("uint32"))) +%!assert (__rand_sample__ (Inf), __rand_sample__ (0)) %!assert (__rand_sample__ (NaN), __rand_sample__ (0)) */