Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

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:
if (strEmpty(input))
var1 = -99999
else
var1 = strToVal(input)

rather than setting it to some number, is there something like:
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.

If (var1==LONG.NaN)
do nothing
else
do something
[799 byte] By [rssmps] at [2007-11-11 8:01:49]
# 1 Re: is it good to set a variable to NaN?
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 at 2007-11-11 21:01:36 >