use a boolean, otherwise you will encounter some interesting problems / errors on the road when your calculated double will actually turn out to be NaN (due to calculation). If you rely on NaN as a signal for "I used this value," then you cannot tell if the "real" unused NaN is.
Not to mention that such an overload of semantics will cause the future reader of your code (even after a few months) to scratch his head in attempts to decipher this clever use .; -)
In general, it is bad practice to overload the value of a variable. At first this may seem pretty, but it will inevitably cause more harm in the future.
As for efficiency - I would recommend the first measure to you and only then worry about optimization. I bet that after running the tests you will find that the difference in speed is significantly lower than the performance noise caused by fluctuations in processor temperature.
source share