Forum Discussion
Altera_Forum
Honored Contributor
21 years agoActually, the NaN will be printed if the value being read is all 1's except the most significant bit. Also, since setting the four globals to zero causes the code to work after initialization. It could still be a memory corruption issue at startup. However, scs is right it is likely that there is some other variable that is initially set to a value that causes an operation to divide 0 by 0. (If you divide non-zero by 0 you actually get infinity.) So if there are other initial conditions, you should check those first.
Another test you could perform to isolate the problem is to set the values to 1 initially. If scs is correct, then the display should change from NaN to infinity (I don't remember the string for infinity). This should help you isolate the problem. Just for reference, below are the defines for the floating point value checks: # define isnanf(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && ((*(long *)&(x) & 0x007fffffL)!=0000000000L)) # define isinff(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && ((*(long *)&(x) & 0x007fffffL)==0000000000L)) # define finitef(x) (((*(long *)&(x) & 0x7f800000L)!=0x7f800000L))