is it good to set a variable to NaN?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: is it good to set a variable to NaN?

  1. #1
    Join Date
    Oct 2005
    Posts
    173

    is it good to set a variable to NaN?

    I've got an input file that is char count delimited.
    so var1 is the first 10 characters of a line and var2 is the second 10 characters of the same line, and so on.

    The problem is that each set of 10 chars could be just an empty string.

    right now, I have the follwoing:
    Code:
    if (strEmpty(input))
       var1 = -99999
    else
       var1 = strToVal(input)
    rather than setting it to some number, is there something like:
    Code:
    if (strEmpty(input))
       var1 = LONG.NaN  // or DOUBLE.NaN, depending on the type of var1
    else
       var1 = strToVal(input)
    If something like this is possible, then the next part is can I use it as a comparison? something like the following.

    Code:
    If (var1==LONG.NaN) 
        do nothing
    else
        do something

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    Nan is a value that you never want to use in your programs. Many hardware architectures generate traps when they encounter such a value, and since NaN is not a legit value, you can't compare it with any other values (this might geremate a trap). Simply choose a special string as an agreed upon value.
    Danny Kalev

Similar Threads

  1. SQL DMO Restores in VB?
    By ObiWan in forum VB Classic
    Replies: 3
    Last Post: 05-23-2006, 10:35 AM
  2. Object variable or With block variable not set
    By Dan-Yeung in forum VB Classic
    Replies: 4
    Last Post: 02-21-2003, 10:56 PM
  3. RUNTIME ERROR saving a recordset
    By Des in forum VB Classic
    Replies: 5
    Last Post: 05-15-2002, 03:16 PM
  4. simple XML APPENDING problem
    By scopee in forum XML
    Replies: 4
    Last Post: 04-13-2001, 03:31 AM
  5. Ted, you're a prince!
    By Georgiana Trigg in forum VB Classic
    Replies: 0
    Last Post: 10-29-2000, 11:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center