This service will be undergoing maintenance at 20:00 UTC, 2017-04-03. It is expected to last about 30 minutes
Bug 143057 - complex<double> / inf gives nan instead of 0
complex<double> / inf gives nan instead of 0
Status: CLOSED UPSTREAM
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
3
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
http://www.cs.berkeley.edu/~wkahan/ie...
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-12-15 20:25 EST by Dmitri A. Sergatskov
Modified: 2007-11-30 17:10 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-12-23 09:18:49 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Dmitri A. Sergatskov 2004-12-15 20:25:31 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5)
Gecko/20041111 Firefox/1.0

Description of problem:
The following program produces "nan" output instead of correct 0.
#include <complex>
#include <iostream>

int main()
{
  std::complex<double> z1(1.0,-1.0);
  double x = 1.0/0.0;
  std::complex<double> z3 = z1/x;

  std::cout
        << "z1: " << z1 << std::endl
        << "x: " << x << std::endl 
        << "z3: " << z3 << std::endl;
  return 0;
}


Version-Release number of selected component (if applicable):
gcc-3.4.3-10 (and quite a few versions before)

How reproducible:
Always

Steps to Reproduce:
1. compile program
2. run it
3.
    

Actual Results:  z1: (1,-1)
x: inf
z3: (nan,nan)


Expected Results:  z1: (1,-1)
x: inf
z3: 0

Additional info:

As alois.schloegl@tugraz.at pointed out
<<<<
Prof. W .Kahan mentions in his "Lecture Notes on the Status of IEEE
754" p.10
http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF

"when (0+3i)/inf is turned naively into (0+3i)*(inf-i)/(inf^2+0^2) it
generates
a NaN instead of the expected 0."
>>>>
Comment 1 Jakub Jelinek 2004-12-23 09:18:49 EST
Please file this upstream (http://gcc.gnu.org/bugzilla), it is better discussed
there.  Reproduceable even with:
#include <stdio.h>

_Complex double a, r;
double b = 1.0 / 0.0;

int
main (void)
{
  __real__ a = 1.0;
  __imag__ a = -1.0;
  r = a / b;
  printf ("%f %f\n", __real__ r, __imag__ r);
  return 0;
}
Comment 2 Dmitri A. Sergatskov 2004-12-23 09:37:17 EST
Done. See
Bug c/19138

Note You need to log in before you can comment on or make changes to this bug.