bugGNU Octave - Bugs: bug #53425, factor.m: Octave producing neither...


bug #53425: factor.m: Octave producing neither error nor correct result

Submitter:  Dildar Sk <hodor123456>
Submitted:  Thu 22 Mar 2018 06:22:55 PM UTC
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Missed Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Dildar Sk Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Tue 17 Apr 2018 12:40:09 AM UTC, comment #5: 

I used the first patch, i.e., not allowing negative numbers as inputs which is just what Matlab does.  I modified it to put all of the validation conditions into a single if block because it is clearer that way.  The final changeset is here http://hg.savannah.gnu.org/hgweb/octave/rev/cac96fd5310d.

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Fri 23 Mar 2018 05:54:07 PM UTC, comment #4: 

If that is the case,
I am providing another patch following,
which will just switch to positive number if it's negative number.
So,I submitted two patches(different method) and whatever Octave community thinks good can choose.But as per MATLAB compatibility
it should throw an error which I submitted first.Another patch attached.

(file #43652)

Dildar Sk <hodor123456>
Fri 23 Mar 2018 04:20:06 PM UTC, comment #3: 

Again, Octave tries to be a superset of Matlab.  We could simply emit an error, as Matlab does.  Alternatively, for negative integers (-N) we could produce factor (N) and then reverse the sign of the first factor.  Sample code:

neg_q = false;
if (q < 0)
  neg_q = true;
  q = -q;

normal algorithm

if (neg_q)
  pf(1) = -pf(1);

I'm not a number theory person so I don't know which option is preferred.  You could ask on the Octave-Maintainers list and maybe that is someone's area of expertise.

Rik <rik5>
Group administrator
Fri 23 Mar 2018 08:05:22 AM UTC, comment #2: 

According to the present documentation and stable implementation, a prime number as defined by Octave's isprime need not be positive. This should be made consistent.

Michael Leitner <mleitner>
Thu 22 Mar 2018 06:28:39 PM UTC, comment #1: 

I changed the warning,error message.
Updated the function and added a test.
Patch attached.

(file #43634)

Dildar Sk <hodor123456>
Thu 22 Mar 2018 06:22:55 PM UTC, original submission:  

When I am trying on MATLAB,

>> factor(-20)

Error using factor (line 23)
N must be a real nonnegative integer.

>> factor(-35)

Error using factor (line 23)
N must be a real nonnegative integer.

Where on Octave,

>> factor(-20)

ans = -20

>> factor(-40)

ans = -40


So,neither the answers are correct nor it's giving any error,warnings.

Dildar Sk <hodor123456>


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

Attach Files:

Attached Files
file #43634:  factor.patch added by hodor123456 (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 rik5 (Posted a comment)
  • -email is unavailable- added by mleitner (Posted a comment)
  • -email is unavailable- added by hodor123456 (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 project members can vote.


    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-04-23 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2018-03-23 hodor123456 Attached File- Added factor_another_method.patch, #43652
    2018-03-22 philipnienhuis StatusNone Confirmed
        Operating SystemGNU/Linux Any
        SummaryOctave producing neither producing error nor correct result where MATLAB is doing factor.m: Octave producing neither error nor correct result
    2018-03-22 hodor123456 Attached File- Added factor.patch, #43634

    Back to the top

    Powered by Savane 3.12