Mercurial > octave
changeset 27458:2f4e8dce06da
Don't print leading spaces before scalar values in interpeter (bug #56939)
* pr-output.cc (make_scalar_format): Reduce width (fw) for all formats so
they display without initial leading spaces. Update BIST tests for new
behavior.
* oct-parse.yy (Fevalc): Update BIST tests for new behavior.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 29 Sep 2019 17:50:52 -0700 |
parents | 70d9746e9011 |
children | 36b610122086 |
files | libinterp/corefcn/pr-output.cc libinterp/parse-tree/oct-parse.yy |
diffstat | 2 files changed, 32 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc Sun Sep 29 17:47:30 2019 +0200 +++ b/libinterp/corefcn/pr-output.cc Sun Sep 29 17:50:52 2019 -0700 @@ -368,9 +368,9 @@ } else if (bank_format) { - fw = (digits < 0 ? 5 : digits + 4); - if (inf_or_nan && fw < 5) - fw = 5; + fw = (digits < 0 ? 4 : digits + 3); + if (inf_or_nan) + fw = 3; rd = 2; } else if (hex_format) @@ -383,17 +383,15 @@ fw = 8 * sizeof (T); rd = 0; } - else if (inf_or_nan || int_only) + else if (inf_or_nan) { - fw = 1 + digits; - if (inf_or_nan && fw < 4) - fw = 4; - - if (int_only) - { - ld = digits; - rd = 0; - } + fw = 3; + } + else if (int_only) + { + fw = digits; + ld = digits; + rd = 0; } else { @@ -413,7 +411,7 @@ rd = (prec > digits ? prec - 1 : prec); } - fw = 1 + ld + 1 + rd; + fw = ld + 1 + rd; } if (! (rat_format || bank_format || hex_format || bit_format) @@ -422,7 +420,7 @@ || fw > pr_output_traits<T>::max_field_width)) { if (print_g) - fmt = float_format (prec+5, prec); + fmt = float_format (prec, prec); else { // e+ddd @@ -431,17 +429,23 @@ if (print_eng) { // -ddd. - fw = 5 + prec + ex; - if (inf_or_nan && fw < 6) - fw = 6; + fw = 1 + prec + ex; + if (inf_or_nan) + { + fw = 3; + ex = 0; + } fmt = float_format (fw, ex, prec - 1, std::ios::fixed); } else { // -d. - fw = 3 + prec + ex; - if (inf_or_nan && fw < 4) - fw = 4; + fw = prec + ex; + if (inf_or_nan) + { + fw = 3; + ex = 0; + } fmt = float_format (fw, ex, prec - 1, std::ios::scientific); } } @@ -3458,7 +3462,7 @@ %! unwind_protect %! format short; %! str = evalc ("x = 1.1; display (x)"); -%! assert (str, "x = 1.1000\n"); +%! assert (str, "x = 1.1000\n"); %! unwind_protect_cleanup %! format (old_fmt); %! format (old_spacing); @@ -3469,7 +3473,7 @@ %! unwind_protect %! format short; %! str = evalc ("display (1.1)"); -%! assert (str, " 1.1000\n"); +%! assert (str, "1.1000\n"); %! unwind_protect_cleanup %! format (old_fmt); %! format (old_spacing); @@ -3939,9 +3943,9 @@ %! ## Test one of the formats %! format long; %! str = disp (pi); -%! assert (str, " 3.141592653589793\n"); +%! assert (str, "3.141592653589793\n"); %! str = disp (single (pi)); -%! assert (str, " 3.1415927\n"); +%! assert (str, "3.1415927\n"); %! new_fmt = format (); %! assert (new_fmt, "long"); %! ## Test resetting format
--- a/libinterp/parse-tree/oct-parse.yy Sun Sep 29 17:47:30 2019 +0200 +++ b/libinterp/parse-tree/oct-parse.yy Sun Sep 29 17:50:52 2019 -0700 @@ -5270,7 +5270,7 @@ %! unwind_protect %! format short; %! str = evalc ("1"); -%! assert (str, "ans = 1\n"); +%! assert (str, "ans = 1\n"); %! unwind_protect_cleanup %! format (old_fmt); %! format (old_spacing); @@ -5293,7 +5293,7 @@ %! unwind_protect %! format short; %! str = evalc ("y = 2"); -%! assert (str, "y = 2\n"); +%! assert (str, "y = 2\n"); %! assert (y, 2); %! unwind_protect_cleanup %! format (old_fmt); @@ -5312,7 +5312,7 @@ %!function [a, b] = __f_evalc () %! printf ("foo"); -%! fprintf (stdout, "bar"); +%! fprintf (stdout, "bar "); %! disp (pi); %! a = 1; %! b = 2;