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!

float holds value of -NAN

Status
Not open for further replies.

Wings

Programmer
Feb 14, 2002
247
US
hi,
A float I'm reading periodically holds a value of -NAN, I was wondering if anyone has run into this problem before and can tell me what it means and a valid way of checking for it? Or a way to check that a float holds a valid float value would be helpful to.

Thanks

 
It just means that it is bigger than the biggest number allowable. With floats, not all the bit patterns are used. Two of the patterns are illegal and they result in Nan or -Nan. Say grandma gives you Nan. What you could do is
Code:
unsigned char* cgran = (unsigned char*) &grandma;
printf ("%02x %02x %02x %02x\n", cgran[0], cgran[1], cgran[2], cgran[3]);
This will give you the hex representation of the sequence that is giving you the Nans. It is normally quite a big number. Could there be an alignment problem with your data?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top