[alt.sys.sun] optimazion bug in C compiler on SS1+?

janowsky@math.rutgers.edu (Steven Janowsky) (03/12/91)

The following program (part of a random number generator) generates NaN
when compiled O2, O3, or O4 but works as expected if O1 or no optimiztion.
SS1+ running 4.0.3c

Any clues? (Please mail response to janowsky@hilbert.rutgers.edu)

#include <stdio.h>
main()
{
  int seed;
  double rand_a, rand_t;

  seed = 34;
  rand_a= -1.0 + 1.0 / 2147483648.0;
  rand_t=seed/2147483648.0;
  printf("%g\n",rand_t);
  rand_t *= 16807;
  rand_t += rand_a * ((int) rand_t);
  if(rand_t >= 1.0) rand_t += rand_a;
  printf("%g\n",rand_t);
}