Mercurial > octave
changeset 33607:338a70ccc1bb
maint: Merge stable to default.
author | Nicholas R. Jankowski <jankowski.nicholas@gmail.com> |
---|---|
date | Sat, 18 May 2024 22:39:14 -0400 |
parents | 631cc5fdf697 (current diff) ca190a4a366c (diff) |
children | 5fba13104493 f958b36069d3 |
files | etc/NEWS.9.md scripts/plot/draw/hist.m |
diffstat | 2 files changed, 32 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/etc/NEWS.9.md Sat May 18 22:26:10 2024 -0400 +++ b/etc/NEWS.9.md Sat May 18 22:39:14 2024 -0400 @@ -6,7 +6,7 @@ ### Improvements and fixes - `hist.m`: Add input validation for `Y` restricting it to 2-D array - (bug #65478). + (bug #65478). Avoid error when `Y` value range is very small (bug #65714). - `cross.m`: Add input validation for `dim` restricting it to a numeric integer valued scalar (bug #65544, bug #65527). - `getframe.m`: Respect pixel ratio (high DPI) of screen with figure
--- a/scripts/plot/draw/hist.m Sat May 18 22:26:10 2024 -0400 +++ b/scripts/plot/draw/hist.m Sat May 18 22:39:14 2024 -0400 @@ -127,8 +127,9 @@ if (nargin == 1 || ischar (varargin{iarg})) n = 10; ## Use integer range values and perform division last to preserve - ## accuracy. - if (min_val != max_val) + ## accuracy. If max - min is less than 20*eps, treat as if min = max to + ## avoid bug #65714 error. + if (min_val != max_val && diff ([min_val, max_val]) > 20 * eps) x = 1:2:2*n; x = ((max_val - min_val) * x + 2*n*min_val) / (2*n); else @@ -153,8 +154,9 @@ error ("hist: number of bins NBINS must be positive"); endif ## Use integer range values and perform division last to preserve - ## accuracy. - if (min_val != max_val) + ## accuracy. If max - min is less than 20*eps, treat as if min = max + ## to avoid bug #65714 error. + if (min_val != max_val && diff ([min_val, max_val]) > 20 * eps) x = 1:2:2*n; x = ((max_val - min_val) * x + 2*n*min_val) / (2*n); else @@ -429,6 +431,31 @@ %! [nb, xb] = hist (b, 30); %! assert ({na, xa}, {nb, xb}); +%!test <*65714> # Avoid error if diff(y) is very small. +%! a = [1, 1+eps, 1+ 15*eps]; +%! hf = figure ("visible", "off"); +%! unwind_protect +%! hax = axes ("parent", hf); +%! hist (hax, a); +%! hp = get (hax, "children"); +%! assert (max (get (hp, "ydata")(:)), 3); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +%!test <*65714> # Avoid error if diff(y) is very small, with specified X. +%! a = [1, 1+eps, 1+ 15*eps]; +%! hf = figure ("visible", "off"); +%! unwind_protect +%! hax = axes ("parent", hf); +%! hist (hax, a, 5); +%! hp = get (hax, "children"); +%! assert (max (get (hp, "ydata")(:)), 3); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + + ## Test input validation %!error <Invalid call> hist () %!error <Y must be real-valued> hist (2+i)