tags:

views:

131

answers:

3

I'm writing a little library where you can set a range; start and end points are doubles. The library has some build-in or calculated default values for that range, but once they are set by the range setting function, there is no way to go back to the default value.

Hence what I like to do is to use the NaN value as the indicator to use the default value, but I haven't found any standard definition of NaN, and reading the gcc manual it says that there are platforms that don't support NaN.

My questions are:

Are there any recent platforms that don't use IEEE 754 floating point numbers? I don't care about some obscured embedded devices, because the lib focuses on platforms with GUI, to be accurate cairo.

And the second question would you use the NaN value as an argument for such a purpose? I have no problem with defining it some where in the header.

+2  A: 

I would not use a NaN for this purpose - beyond the issue of just which NaN to use (and there are many), it would be better to add a function call API to reset to the defaults.

Lance Richardson
+3  A: 

NaN is not equal to any number, not even to itself. Hence, using it as an indicator will lead to convoluted code or even bugs. I would not use it in this way.

Don Reba
Man do I ever know what you mean regarding convoluted bugs... The first time I ran into weird NaN stuff, it took me hours to realize that NaN != NaN...
Erik Forbes
... and that that was the source of my troubles.
Erik Forbes
+1  A: 

NaNs are kind of weird to deal with in code, and I certainly wouldn't like a library to use them purposes which they are not made for.

Edit: Another problem that I just thought of is that if a calculation results in NaN, and it is passed as the argument, you will get unintended behavior. For example:

MyFunc(SomeCalculation()); //if SomeCalculation() is assumed to not be NaN,
                           //this will cause unintended behavior
Zifre