bugGNU Octave - Bugs: bug #67717, Octave manual needs discussion of...

 
 

bug #67717: Octave manual needs discussion of complex number narrowing

Submitter:  None
Submitted:  Tue 18 Nov 2025 02:00:29 PM UTC
   
 
Category:  Documentation Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Documentation
Status:  Confirmed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 9.4.0
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

Tue 18 Nov 2025 06:42:31 PM UTC, comment #3: 

You've proved it.  We are having terrible problems with AI-bots asking auto-generated questions designed to solicit feedback from a real human which they then use to improve their LLMs.  It sucks a lot of time away from actually developing and improving Octave.

The issue you are encountering is the "narrowing" of complex numbers to real numbers.  When Matlab detects that a complex number has an imaginary part that is zero, it replaces that nominally complex number with just the real part.  This saves memory and normally has no side effects since a complex number with zero imaginary part is, in fact, real.  Octave strives to be Matlab-compatible and therefore does the same thing.  Here is a sample session showing how narrowing works in practice.

octave:2> x = 5 + 1i
x =  5 + 1i
octave:3> iscomplex (x)
ans = 1
octave:4> y = x - 1i
y = 5
octave:5> iscomplex (y)
ans = 0

In the code you posted "5+0i" is replaced by "5" before the function isprime() ever sees any input.

If you must guarantee that a number is represented with both a real and imaginary part then use the function complex().  But note, that the interpreter performs narrowing whenever it can, not just on creation.  So if you create a number with complex() which is actually a real number, it will be reduced to real at the first opportunity.  See the Octave session below.

octave:10> x = complex (5,0)
x =  5 + 0i
octave:11> iscomplex (x)
ans = 1
octave:12> x = x + 1
x = 6
octave:13> iscomplex (x)
ans = 0

One thing that I notice now is that there is no adequate discussion of narrowing in the Octave manual.  I'm going to change the issue report to note that.


Rik <rik5>
Group administrator
Tue 18 Nov 2025 04:50:50 PM UTC, comment #2: 

What are you a self-appointed AI gatekeeper?

I regret filing a bug report.

Don't bother fixing it. I'll move to Numpy like the rest of my team.

Anonymous
Tue 18 Nov 2025 02:28:13 PM UTC, comment #1: 

Prove that you are not AI-bot and we will respond.

Rik <rik5>
Group administrator
Tue 18 Nov 2025 02:00:29 PM UTC, original submission:  

Octave is not being consistent between "a + b*i" and "complex (a, b)". This means that "5+0i" becomes a double but "complex (5,0)" is a complex number.


octave:3> isprime (5+0i)
ans = 1

octave:4> isprime (complex (5,0))
ans = 0


5 is prime in integers but not in complex, because 5 = (1 + 2i) * (1 - 2i).

The number 5+0i should be parsed as complex because it has an explicit "a + bi" format.

Anonymous

 

Attached Files

Attached Files
file #57951:  bug67717.patch added by sgtquickscoper (1.5KiB - text/x-patch - doc: added documentation for narrowing of complex numbers in numbers.txi (bug #67717))

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

Attach Files:
   
   
Comment:
   

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

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

    Votes

    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.

     

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

    History

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-12-10 sgtquickscoper Attached File- Added bug67717.patch, #57951
    2025-11-18 rik5 CategoryNone Documentation
        Item GroupNone Documentation
        StatusNeed Info Confirmed
        Summarycomplex number is not being parsed consistently Octave manual needs discussion of complex number narrowing
    2025-11-18 rik5 StatusNone Need Info

    Back to the top

    Powered by Savane 3.16-a7ba.
    Corresponding source code