I've read the informative posts on NaN use in Fortran comparisons (here and here) and I think I've got a handle on roughly what's going on.
My question is more about NaN use in general.
Say I have a collection of reals and I don't know, yet, what their values are. So I set them all to be NaN and, effectively, I use NaN to mean, in part, 'unallocated'. There seems to be some debate as to whether this is a good idea and I've read recommendations to use huge(1.0) or some other 'magic number' instead.
But using NaN seems to have real benefits in that that any calculation involving any variable of value NaN will result in a NaN. Which is helpful (and probably 'correct' in a mathematical sense).
For example if x is set to NaN, and y is 1.23 then
z = x + y
z = x - y
z = x * y
z = x / y
will always result in z being NaN (at least it does with Intel v18 on Windows) - which is what I want: z is unknown because x is unknown.
So - is this an acceptable use of NaN? Or am I creating problems that I'm not aware of yet?