octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #61968] pow2 with two arguments is not Matlab


From: Kai Torben Ohlhus
Subject: [Octave-bug-tracker] [bug #61968] pow2 with two arguments is not Matlab compatible
Date: Tue, 1 Feb 2022 00:41:46 -0500 (EST)

URL:
  <https://savannah.gnu.org/bugs/?61968>

                 Summary: pow2 with two arguments is not Matlab compatible
                 Project: GNU Octave
            Submitted by: siko1056
            Submitted on: Tue 01 Feb 2022 02:41:45 PM JST
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: In Progress
             Assigned to: siko1056
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
                 Release: 7.0.90
         Discussion Lock: Any
        Operating System: Any

    _______________________________________________________

Details:

>From the Matlab documentation
https://www.mathworks.com/help/matlab/ref/pow2.html:

> The syntax Y = pow2(X,E) corresponds to the ANSI® C function ldexp() and
the IEEE® floating-point standard function scalbn(). The result Y is computed
quickly by simply adding E to the floating-point exponent of X.

Octave so far simply computes
https://hg.savannah.gnu.org/hgweb/octave/file/66456820ff59/scripts/specfun/pow2.m#l57


Y = X .* 2 .^ E


Some test cases for verification (fails in Octave 7):


Yexpect = str2num (char ({'1','pi','-3','eps','realmax','realmin'}'))
X = str2num (char ({'1/2','pi/4','-3/4','1/2','1-eps/2','1/2'}'));
E = [1 2 2 -51 1024 -1021]';
Y = pow2 (X, E)
isequal (Y, Yexpect)  % true == 1


Especially the complex part is ignored in the TWO argument call.  Sparse and
Single type are preserved in the output.


>> f = [1+1i, 1]; e = 2; y1 = pow2(f,e), y2 = f.*2.^e 
Warning: Imaginary part is ignored. 
y1 = 4     4
y2 = 4.0000 + 4.0000i   4.0000 + 0.0000i

>> f = 1; e = [1 + 1i, 1 + 1i]; y1 = pow2(f,e), y2 = f.*2.^e
Warning: Imaginary part is ignored.
y1 = 2     2
y2 = 1.5385 + 1.2779i   1.5385 + 1.2779i


I am working on a patch.  As nice side effect the function will move from
m-code to C++ code.





    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?61968>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]