Mercurial > octave
changeset 30860:fc045a84cb33
maint: Merge stable to default.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Wed, 23 Mar 2022 18:28:24 +0100 |
parents | 820466e45a93 (current diff) df26decca96b (diff) |
children | 070d5b04a0ac |
files | libinterp/octave-value/ov.cc |
diffstat | 2 files changed, 8 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov.cc Wed Mar 23 15:36:08 2022 +0100 +++ b/libinterp/octave-value/ov.cc Wed Mar 23 18:28:24 2022 +0100 @@ -3250,16 +3250,16 @@ double abs_increment = std::abs (increment); - if (abs_increment > max_val) + // Technically, this condition should be `abs_increment > max_val`. + // But intmax('uint64') is not representable exactly as floating point + // number. Instead, it "rounds" up by 1 to 2^64. To account for + // this, use the following expression which works for all unsigned + // integer types. + if ((abs_increment-1.) >= max_val) return 1; UT unsigned_increment = range_increment<T> (increment); - // If the increment wasn't zero before but it is now, the cast to UT - // wrapped around. The range can only have one value. - if (unsigned_increment == 0) - return 1; - return range_numel_aux (base, unsigned_increment, limit); }
--- a/test/range.tst Wed Mar 23 15:36:08 2022 +0100 +++ b/test/range.tst Wed Mar 23 18:28:24 2022 +0100 @@ -608,7 +608,7 @@ %! endfor ## integer range with large double increments -%!test <62212> # ascending ranges +%!test <*62212> # ascending ranges %! types = {"int8", "int16", "int32", "int64"}; %! for i_type = 1:numel (types) %! assert (intmin (types{i_type}) : -double (intmin (types{i_type})) : intmax (types{i_type}), ... @@ -621,7 +621,7 @@ %! [intmin(types{i_type}), intmax(types{i_type})-1]); %! endif %! endfor -%!test <62212> # descending ranges +%!test <*62212> # descending ranges %! types = {"int8", "int16", "int32", "int64"}; %! for i_type = 1:numel (types) %! assert (intmax (types{i_type}) : double (intmin (types{i_type})) : intmin (types{i_type}), ...