bugGNU Octave - Bugs: bug #51556, function isreal applied on complex...

 
 

bug #51556: function isreal applied on complex numbers with zero imaginary part

Submitted by:  Ernst Reissner <ernstreissner>
Submitted on:  Mon 24 Jul 2017 12:02:48 PM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: NoneAssigned to: None
Originator Name: Open/Closed: Closed
Release: devOperating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Mon 24 Jul 2017 02:23:01 PM UTC, comment #4:

In Matlab 2016a, sorry not the latest, "isreal (0i)" returns true. The sequence from comment #2 returns the results in comments. So I guess this report can be closed as invalid.

Pantxo Diribarne <pantxo>
Project Member
Mon 24 Jul 2017 02:04:33 PM UTC, comment #3:

To confirm JWE's presumption, Matlab r2017b prerelease gives:

and r2016b does exactly the same.

Furthermore,

Philip Nienhuis <philipnienhuis>
Project Member
Mon 24 Jul 2017 01:26:20 PM UTC, comment #2:

In Matlab, (and Octave, for compatibility reasons) if you want to create a complex value with a zero imaginary part, you need to use something like "complex (r, 0)". And even then, if you use that value in an expression like this:

you will get a real value as the final result because of the automatic complex -> real conversion rules for (nearly all) expression results.

I'm certainly not claiming this is mathematically correct or necessarily the best programming language design. But it is the way Matlab works and we have to do the same for compatibility reasons. If we didn't, we'd be constantly getting bug reports that Octave fails on code that works perfectly well in Matlab.

John W. Eaton <jwe>
Project Administrator
Mon 24 Jul 2017 01:16:41 PM UTC, comment #1:

I'm pretty sure that Matlab automatically narrows the result of the expression 0i to be real, so that isreal (0i) actually returns true.

Could someone please verify with the latest Matlab?

John W. Eaton <jwe>
Project Administrator
Mon 24 Jul 2017 12:02:48 PM UTC, original submission:

According to
https://www.mathworks.com/help/matlab/ref/isreal.html

isreal(x) determines whether a has real type.
Consequently, isreal(0i) is false in matlab.
also isreal([0i 1]) is just false, a single scalar value
because the type is meant, not zero imaginary part in all components.

The current usage of isreal(A)
which means imag(A) is nonzero may be substituted by

~any(imag(A)).

Ernst Reissner <ernstreissner>

 

(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 rik5 (Updated the item)
  • -unavailable- added by pantxo (Posted a comment)
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by ernstreissner (Submitted the item)
  • -unavailable- added by ernstreissner
  •  

    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 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 24 Jul 2017 03:28:49 PM UTCrik5Open/ClosedOpen=>Closed
    Mon 24 Jul 2017 12:02:48 PM UTCernstreissnerCarbon-Copy-=>Added -unavailable-

    Back to the top


    Powered by Savane 3.1-cleanup1