Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with NaN

Status
Not open for further replies.

thumpkidd9

Programmer
Mar 27, 2005
42
US
I am trying to do some simple division and I am having a problem with floats. I'm not sure where the problem is but I think in here.
Code:
float A4[maxArray] = {0.0, 0.0, 0.0, 0.0, 0.0};
float lot[maxArray]= {0.0, 0.0, 0.0, 0.0, 0.0};

A4[1] = (num_blk1/tries1);
A4[2] = (num_blk2/tries2);
A4[3] = (num_blk3/tries3);
A4[4] = (num_blk4/tries4);

for(a=1;a<5;a++){
    printf("lot[%d] = %.3f: %.3f\n",a,lot[a],A4[a]);
}// for

All I want to do is check
Code:
if(lot[4]==lot[a]) var=a;

but what comes out in the print statement is

lot[1] = 0.000: NaN
lot[2] = 0.000: NaN
lot[3] = 0.000: NaN
lot[4] = 0.000: NaN

all of A4[] is = NaN for some reason. "num_blk" and "tries" are both floats themselves, also initialized to 0.0. Any ideas?
 
all of A4[] is = NaN for some reason. "num_blk" and "tries" are both floats themselves, [red]also initialized to 0.0[/red]. Any ideas?
Dividing by zero.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top