c/5277: NaN unexpectedly

long@stsci.edu long@stsci.edu
Fri Jan 4 11:06:00 GMT 2002


>Number:         5277
>Category:       c
>Synopsis:       NaN unexpectedly
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 04 11:06:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Knox S. Long
>Release:        gcc-2.96-81
>Organization:
>Environment:
Redhat 7.1  (on a Dell Dimension 1 Ghz machine)
glibc-2.2.4-19.3
>Description:
I am seeing a problem in which simple double precision math
occasionally generates NAN problems.  The probalem is odd
because if on printf's the offending variable, and reprints 
the result, the NAN problem goes away

Here is an example code fragement where this can occur.
double
thierry_velocity (x, v)
     double x[];
     double v[];
{
  int n;
  double r, speed;
  double frac,z;
  double length ();

z=x[0]*x[0]+x[1]*x[1]+x[2]*x[2];
if(sane_check(z)){
        printf("%f\n",z);
        z=x[0]*x[0]+x[1]*x[1]+x[2]*x[2];
        printf("%f\n",z);
}
  r = length (x);

...

where sane_check simply checks to see whether x is finite, e.g.
int
sane_check (x)
     double x;
{
  int i;
  if ((i = finite (x)) == 0)
    {
      Error ("sane_check: %d %e\n", i, x);
      return (-1);
    }
  return (0);
}


There was some discussion of a similar problem on the web 
associated with gcc 2.95.1. and even a reference to a bug
report which I could not locate.

I ran the identical program on a Sun (with gcc 2.95) and
did not see the problem.




>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list