File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NaN

 
Garann Means
Ranch Hand
Posts: 214
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I compare a variable containing an int to Float.NaN and get the results I intend to get?
I get the variable's value from my database and, if it contains erroneous data, I want to skip an if structure that will try to perform arithmatic on it. Will testing it against Float.NaN work?
Thanks,
g.
 
Bonnie Beach-Morin
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, technically you can. However, to do so would be somewhat pointless since the result would almost always be false. If the column you retrieve contains a null value, the getInt() method will return 0.
Bear in mind that (Float.NaN == Float.NaN) will return false.
 
Bonnie Beach-Morin
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By-the-by, what do you consider to be 'erroneous data?'
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I compare a variable containing an int to Float.NaN and get the results I intend to get?
I suppose it depends what you intend. Probably you want to be using Double.isNaN(double) rather than ==. (Or use Float.isNaN(float) for float.)
[ July 02, 2002: Message edited by: Jim Yingst ]
 
Garann Means
Ranch Hand
Posts: 214
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bonnie,
Erroneous data would be anything written to the 'field' in the database that was corrupted or simply entered wrong. It's a legacy database, and the 'fields' are just characters from a start index to an end index, making it easy for people to be off one index number and overwrite the beginning or end of my 'field' with non-numeric (for my purposes, erroneous) data.
-------------------------------------
I did test this in VisualAge for Java's 'scrapbook', the quickest debugging tool I have, and it seemed to work out. But it sounds like the concensus is that I can't rely on those results for all cases. Since the variable needs to be an int before and after this test, the following sounds like the best solution:

Jim and Bonnie, do you agree?
Thank you!
g.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic