<p>I have double (or float) variables that might be "empty", as in holding no valid value. How can I represent this condition with the built in types float and double?</p>

<p>One option would be a wrapper that has a float and a boolean, but that can´t work, as my libraries have containers that store doubles and not objects that behave as doubles. Another would be using NaN (std::numeric_limits). But I see no way to check for a variable being NaN.</p>

<p>How can I solve the problem of needing a "special" float value to mean something other than the number?</p>

We have done that by using NaN:
```
```
double d = std::numeric_limits<double>::signaling_NaN();
bool isNaN = (d != d);
```
```
NaN values compared for equality against itself will yield false. That's the way you test for NaN, but which seems to be only valid if
```
std::numeric_limits<double>::is_iec559
```
is true (if so, it conforms to ieee754 too).
In C99 there is a macro called
```
isnan
```
for this in
```
math.h
```
, which checks a floating point number for a NaN value too.