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

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

[Octave-bug-tracker] [bug #60786] mpower: negative scalar to power of ma


From: John W. Eaton
Subject: [Octave-bug-tracker] [bug #60786] mpower: negative scalar to power of matrix containing non-integers returns nan
Date: Tue, 29 Jun 2021 22:49:03 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0

Follow-up Comment #17, bug #60786 (project octave):

RE: comment #14 and the changeset
http://hg.savannah.gnu.org/hgweb/octave/rev/004e63a7a50, I don't think we get
the expected result if we just use std::pow.  For example, with the following
program


#include <iostream>
#include <complex>

int main (void)
{
  std::complex<double> c (0.0, 0.0);
  double d = 0.0;

  std::cerr << std::pow (d, d) << std::endl;
  std::cerr << std::pow (d, c) << std::endl;
  std::cerr << std::pow (c, d) << std::endl;
  std::cerr << std::pow (c, c) << std::endl;

  return 0;
}


I see


1
(nan,nan)
(-nan,-nan)
(nan,nan)


so it doesn't appear that std::pow for complex values with zero imaginary part
gives the same result as converting to double and then calling std::pow
(double, double).

The differences aren't limited to just the complex (0, 0) case.  If I change
the program above to set c = (-2, 0) and d = -2, I see:


0.25
(0.25,6.12323e-17)
(0.25,6.12323e-17)
(0.25,6.12323e-17)


I've been looking at bug #60846 and noticed that complex (0, 0) ^ complex (0,
0) produced NaNs instead of 1 as 0 ^ 0 does.  We have this problem for the
scalar operators and for element-wise operators for both full and sparse
matrices, so this is nothing new but it does appear to be incompatible
behavior with Matlab.

    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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