bugGNU Octave - Bugs: bug #55919, Format short|long g does not align...


bug #55919: Format short|long g does not align numbers within matrices

Submitted by:  None
Submitted on:  Thu 14 Mar 2019 02:44:44 PM UTC  
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  5.1.0
Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Fri 20 Sep 2019 06:47:44 PM UTC, comment #7: 

I checked in a fix on the development branch here https://hg.savannah.gnu.org/hgweb/octave/rev/e0134184c1fd.  This will be a part of the 6.1 release of Octave.  If you need it sooner, you can get the code from the Mercurial repository and build from scratch.

Marking as fixed and closing report.

Rik <rik5>
Project Administrator
Mon 19 Aug 2019 01:35:42 PM UTC, comment #6: 

I too have this problem. It regressed from 4.2 to 5.1. Does anyone know a workaround? Thanks, Ben.

Sat 16 Mar 2019 03:11:16 PM UTC, comment #5: 

It looks like "g" mode in pr-output.cc always calls float_format with default arguments, which sets field width to 0 (as wide as necessary) but for non-g modes, float_format is called with 4 arguments that specify a minimum field width. It looks like setting a minimum field width in g-mode should take care of both problems -- it will allow sufficient space between elements and not try to pack too many in one line. Thoughts?

Sat 16 Mar 2019 02:42:49 PM UTC, comment #4: 

To see the combined effect of both OP and Rik, try:

x = pi(4,300) + (1:300) + (1:4)'; # ranges from 5.14 to 307.14
format; x
format short; x
format short g; x

Sat 16 Mar 2019 02:27:47 PM UTC, comment #3: 

I have this same problem, and it's worse when printing matrices with many columns. Try this:

x = dec2base(0:255,4,4)-'0')'
format short g

In normal mode, on my display, it correctly gives Columns 1 through 47, 48 through 94 ... 236 to 256 and the matrix has 4 rows.

In "g" mode, it erroneously gives Columns 1 through 94, 95 through 188, 189 through 256, but the display can accommodate only 47 numbers per row with spaces, so each line of the matrix spills over to 2 lines of unequal length, and the display is a mess.

The calculation of the width of each element in "g" mode forgets to add the space between elements, and tries to pack too many elements per line.

Thu 14 Mar 2019 03:58:16 PM UTC, comment #2: 

Just for reference, Matlab behaves the same as Octave 4.2.1 and right aligns the value "1.5" in the second column.

Rik <rik5>
Project Administrator
Thu 14 Mar 2019 03:50:55 PM UTC, comment #1: 

Confirmed.  This is a regression from version 4.2.1 where this worked.  I've changed the Operating System to Any since this also affects Linux and presumably Mac as well.

A more repeatable example that does not rely on random numbers is

x = pi (3,3);
x(2,2) = 1.5;
format short g
x =

  3.1416  3.1416  3.1416
  3.1416  1.5  3.1416
  3.1416  3.1416  3.1416

The only format that is affected is the 'g' format (short or long) because this format does not print unecessary digits.

The same example run on version 4.2.1 produced

x =

      3.1416      3.1416      3.1416
      3.1416         1.5      3.1416
      3.1416      3.1416      3.1416

The decimal point is not aligned, but at least the columns are.

Rik <rik5>
Project Administrator
Thu 14 Mar 2019 02:44:44 PM UTC, original submission:  

It's OK for format to not align decimals in "short g" or "long g" mode, but not aligning spaces makes it difficult to read matrices.

>> clc; m = rand(3,4) * 10; format ; format compact; pi .^ m, format short g ; format compact; pi .^ m
ans =
   63347.42037   19535.77952    2095.81019    7855.03927
       3.87267    1578.58116     117.64081      22.98961
      81.90035      44.51271       5.07318     339.91538

ans =
  63347  19536  2095.8  7855
  3.8727  1578.6  117.64  22.99
  81.9  44.513  5.0732  339.92



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-09-20 rik5 StatusConfirmed => Fixed
        Open/ClosedOpen => Closed
    2019-03-14 rik5 CategoryNone => Interpreter
        Item GroupNone => Regression
        StatusNone => Confirmed
        Operating SystemMicrosoft Windows => Any
        SummaryFormat does not align space within matrices => Format short|long g does not align numbers within matrices

    Back to the top

    Powered by Savane 3.5