https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89991

            Bug ID: 89991
           Summary: Complex numbers: Calculation of imaginary part is not
                    correct
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: t.sprodowski at web dot de
  Target Milestone: ---

Following calculation of the complex number leads to a wrong imaginary part:


#include <complex>
#include <iomanip>
#include <iostream>

int main(int argc, char *argv[])
{
  std::complex<double> val = std::complex<double>(-1.8425031517782417e-07,
-0.0);
  std::complex<double> testExp = std::pow(val, 0.5);
  std::cout << "textExp: " << std::setprecision(30) << testExp << std::endl;
  return 0;
}

Result is:
(2.6283607659835830609796003783e-20,-0.000429243887758258178214548772544), but
it should be
(2.628360765983583e-20, 0.0004292438877582582), obtained from Visual Studio,
MATLAB and Octave.

Compilation was done with gnu 8.2.0 and 7.3.0 on Ubuntu 18.04:

g++ -c -pipe -g -std=gnu++1y -Wall -W -D_REENTRANT -fPIC
-DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_CORE_LIB -I../testPrecision -I.
-isystem /usr/include/x86_64-linux-gnu/qt5 -isystem
/usr/include/x86_64-linux-gnu/qt5/QtCore -I.
-I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o main.o
../testPrecision/main.cpp

Reply via email to