Read back infinities and NaNs from text archives - #387
Conversation
An infinity is written as "inf" and a NaN as "nan", because that is what the stream writes, and extraction of a floating point number then refuses both: it takes digits and little else, in libstdc++ and in the Microsoft library alike. So the library wrote text and XML archives which it could not read back. Recognize the two forms when reading, rather than change what is written, so that archives already in existence start loading instead of staying unreadable. Fixes #386.
|
consider creating as special tag for NaN etc not dependent on the compiler. This would make the serialization library independent of any differences between compilers and/or standard libraries. Of course then one would have to be be checking the old compiler dependent tags and/or perhaps the library version number so I wouldn't be more efficient, just reduce future surprises. FYI It's amazing to me that this hasn't come up before. It's also interesting to consider the possibility of handling this out side of streams. As it stands now the binary archive would not be portable between compiles. Same for non-stream archives. Think about this. Again, consider this a suggestion rather than a "fix" |
|
It is tricky to detect NaNs when writing; sometimes it depends on the optimization level. For example, std::isnan might always return false at some optimization levels. You can compare with bit patterns, but I am not sure how portable it is. Same with infinity; I wonder if this is a limitation of the underlying stream that the archive type must accept. In any case, don't forget about infinities and NaNs in std::complex. :) |
An infinity is written as "inf" and a NaN as "nan", because that is what the stream writes, and extraction of a floating point number then refuses both: it takes digits and little else, in libstdc++ and in the Microsoft library alike. So the library wrote text and XML archives which it could not read back.
Recognize the two forms when reading, rather than change what is written, so that archives already in existence start loading instead of staying unreadable.
Fixes #386.