Bug 143057 - complex<double> / inf gives nan instead of 0
Summary: complex<double> / inf gives nan instead of 0
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 3
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL: http://www.cs.berkeley.edu/~wkahan/ie...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-12-16 01:25 UTC by Dmitri A. Sergatskov
Modified: 2007-11-30 22:10 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-12-23 14:18:49 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Dmitri A. Sergatskov 2004-12-16 01:25:31 UTC
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 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 14:18:49 UTC
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 14:37:17 UTC
Done. See
Bug c/19138


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