Robert Ramey wrote:
There has been work in trying to make a portable implementation of stream input/output of varying types of NaN's. This has been hampered by the fact that the handling of NaN's varies accross implementation so it doesn't seem possible to make "transportable" archives which can be guarenteed to recover the same type of NaN that has been saved.
For what it's worth, my personal view is that the attempt to save an undefined value - be it a NaN, undefined bool or whatever should be considered an error and trapped as soon as possible. Implementing this would be fairly easy with a custom stream facet which can be optionally attached to any stream. This would leave the choice as to what behavior he desires in the hands of the user.
But no one has been motivated to actually do this so far.
I'm working on such facets still for handling non-finite floating point numbers (infinity and NaN). I have code that works fine for float and double, but there are still some problems to be resolved for long double. And yes, the code has a facility for trapping infinity and NaN, if you so wish. --Johan