Mercurial > hg > octave-nkf
changeset 18775:37c300acfcfd stable
don't truncate when casting char to uintN values (bug #42054)
* oct-inttypes.h (octave_int<T>::octave_int (char)):
New special case constructor.
* oct-inttypes.cc: New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 05 Apr 2014 15:09:09 -0400 |
parents | 6535cb2b8e23 |
children | c644ed73c6ce |
files | liboctave/util/oct-inttypes.h scripts/plot/draw/fplot.m |
diffstat | 2 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/util/oct-inttypes.h +++ b/liboctave/util/oct-inttypes.h @@ -830,6 +830,11 @@ octave_int (T i) : ival (i) { } + // Always treat characters as unsigned. + octave_int (char c) + : ival (octave_int_base<T>::truncate_int (static_cast<unsigned char> (c))) + { } + octave_int (double d) : ival (octave_int_base<T>::convert_real (d)) { } octave_int (float d) : ival (octave_int_base<T>::convert_real (d)) { }
--- a/scripts/plot/draw/fplot.m +++ b/scripts/plot/draw/fplot.m @@ -146,10 +146,10 @@ ## problems with the current solution. while (n < 2^18) # Something is wrong if we need more than 250K points - yi = interp1 (x0, y0, x, "linear"); + yi = interp1 (x0, y0, x, "linear") ## relative error calculation using average of [yi,y] as reference ## since neither estimate is known a priori to be better than the other. - err = 0.5 * max (abs ((yi - y) ./ (yi + y))(:)); + err = 0.5 * max (abs ((yi - y) ./ (yi + y))(:)) if (err < tol || abs (err - err0) < tol/2) ## Either relative tolerance has been met OR ## algorithm has stopped making any reasonable progress per iteration.