bugGNU Octave - Bugs: bug #56936, format short displays 6, rather...

 
 

bug #56936: format short displays 6, rather than 5, significant digits as documented

Submitter:  Rik <rik5>
Submitted:  Mon 23 Sep 2019 06:02:05 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 05 Apr 2020 11:25:59 PM UTC, comment #5: 

I know it is pointless saying that MATLAB is wrong but in this case MATLAB is wrong! Left-hand zeros are not significant. The correct result to 5 significant figures is "0.33333". For the default format short, output_precision(5), the number of significant digits shown varies between 4 and 7:

octave:1> version
ans = 7.0.0
octave:2> format short
octave:3> output_precision
ans = 5
octave:4> 0.00123456
ans = 1.2346e-03
octave:5> 0.0123456
ans = 0.012346
octave:6> 0.123456
ans = 0.1235
octave:7> 1.23456
ans = 1.2346
octave:8> 12.3456
ans = 12.346
octave:9> 123.456
ans = 123.46
octave:10> 1234.56
ans = 1234.6
octave:11> 12345.6
ans = 1.2346e+04
octave:12> 123456
ans = 123456
octave:13> 1234567
ans = 1234567
octave:14> 12345678
ans = 1.2346e+07


Robert Jenssen <morgawr>
Fri 11 Oct 2019 04:30:12 AM UTC, comment #4: 

Yes, that's right.  The leading zero is considered significant, at least according to Matlab.  Testing with R1029b gives "0.3333" for the example you mentioned.

Rik <rik5>
Group administrator
Fri 11 Oct 2019 12:08:48 AM UTC, comment #3: 

Rik - I haven't built the default branch locally to test this myself yet, but according to some continuous build logs I have, this or related changes now have Octave printing only 4 significant digits for some numbers, for example


>> 1/3
ans = 0.3333


Is this intentional?

Mike Miller <mtmiller>
Group Member
Fri 27 Sep 2019 09:04:13 PM UTC, comment #2: 

Fixed in this changeset https://hg.savannah.gnu.org/hgweb/octave/rev/ce0399fa017a.

Closing report.

Rik <rik5>
Group administrator
Mon 23 Sep 2019 10:13:51 PM UTC, comment #1: 

Attached is a patch which resolves the issue for the example in this bug report.  I only made the change to make_real_matrix_format because this is still a work in progress.

What should happen when we have small numbers?  Should we end up printing a lot of zeros?  That is what happens now.


x*1e-6
ans =

  -0.0000031416
              0
   0.0000031416


Before, we would switch over to scientific notation at a certain point.  These are the results from version 3.4.3


octave-3.4.3:5> x*1e-3
ans =

  -0.0031416
   0.0000000
   0.0031416

octave-3.4.3:6> x*1e-4
ans =

  -3.1416e-04
   0.0000e+00
   3.1416e-04


I've asked on the mailing list for opinions.


(file #47565)

Rik <rik5>
Group administrator
Mon 23 Sep 2019 06:02:05 PM UTC, original submission:  

According to the documentation, "format short" (default), should display 5 significant figures.  It does so for scalars, but not for matrices.


octave:16> format short
octave:17> x = pi
x =  3.1416
octave:18> x = [-pi;0;pi]
x =

  -3.14159
         0
   3.14159

octave:19> diary off


For comparison, Matlab displays "3.1416" in both cases.

This is probably a bug in pr-output.cc in the routines make_real_matrix_format, make_complex_matrix_format, make_complex_scalar_format).  It looks like the number of figures to the right of the decimal point is being set at the precision.


Rik <rik5>
Group administrator

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #47565:  56936.patch added by rik5 (1KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-09-27 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2019-09-23 rik5 Attached File- Added 56936.patch, #47565

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code