bugGNU Octave - Bugs: bug #39735, printf with empty arguments is...

 
 

bug #39735: printf with empty arguments is inconsistent with Matlab

Submitted by:  None
Submitted on:  Fri 09 Aug 2013 09:16:14 AM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: ConfirmedAssigned to: None
Originator Name: Michael LeitnerOriginator Email: -unavailable-
Open/Closed: OpenRelease: 3.6.2
Operating System: GNU/Linux

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

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

 

Mon 26 Aug 2013 07:45:23 PM UTC, comment #2:

Jordi,

I can confirm Matlab behaves as you indicated.

Ben Abbott <bpabbott>
Project Member
Fri 09 Aug 2013 01:24:52 PM UTC, comment #1:

Okay, I'm told Matlab does this:

So we should do the same, no matter how stupid it is.

Jordi GutiƩrrez Hermoso <jordigh>
Project Administrator
Fri 09 Aug 2013 09:16:14 AM UTC, original submission:

Consider:

For me, this is inconsistent behaviour, I would expect the last command to give empty output. It seems that this is connect to the feature of being able to output matrices that "are not exact multiples of the number of conversions in the format template":

Without looking into the code, I cannot imagine the logic leading to these results, for me the most obvious implementation would be to integer-divide the number of supplied elements by the number of conversions in the output string, call C's printf accordingly and special-case the remaining elements (by cutting the output string and pass it once more to C's printf). This would give my expected behaviour. By the way, what does MATLAB do?

At the very least, the observed behaviour is a documentation bug. In 14.2.5 it says "If more than one value is to be printed in a single call, the output functions do not return to the beginning of the format template when moving on from one value to the next. This can lead to confusing output if the number of elements in the matrices are not exact multiples of the number of conversions in the format template." But here it is not more than one value that is to be printed, and also the number of elements is an exact (should say: integer) multiple of the number of output conversions.

Going a step further, I would find an added feature useful: add m and v as type modifier characters, which in the hitherto syntax are being ignored. The output should be:

Initial and trailing spaces/newlines would be left to debate, but I would keep them at a minimum, as the user can supply them in the format string. This could be implemented rather easily by a pass over the output conversion string looking for v or d in a conversion and generating a new string, substituting a %v by the corresponding sequence of %**, given by length(corresponding argument)). Obviously, mixing a %d with a %vd in a single call with both vector arguments would give an awkward situation.

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by bpabbott (Posted a comment)
  • -unavailable- added by jordigh (Posted a comment)
  •  

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

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 09 Aug 2013 01:25:57 PM UTCjordighItem GroupInaccurate Result=>Matlab Compatibility
      Summaryprintf behaviour is inconsistent for matrix arguments=>printf with empty arguments is inconsistent with Matlab
    Fri 09 Aug 2013 01:24:52 PM UTCjordighStatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup