Opened 9 years ago
Last modified 7 years ago
#9810 reopened Feature Requests
boost serialization: deserialization from boost txt archive fails on -nan for double
Reported by: | Owned by: | Robert Ramey | |
---|---|---|---|
Milestone: | To Be Determined | Component: | serialization |
Version: | Boost 1.55.0 | Severity: | Problem |
Keywords: | Cc: |
Description
A double gets correctly serialized to "-nan". Deserializing it leads to 'boost::archive::archive_exception'
what(): input stream error
when used with a text archive.
Change History (5)
comment:1 by , 9 years ago
Component: | None → serialization |
---|---|
Owner: | set to |
comment:2 by , 9 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Type: | Bugs → Feature Requests |
comment:3 by , 9 years ago
Sorry but that is not current behavior. Boost happily serializes -nan to -nan in a text format (it looks like 5 6 -8 -nan 8 2 ...), just the deserializing fails.
comment:4 by , 8 years ago
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
comment:5 by , 7 years ago
I was taken by this behaviour also (in Serialization 1.60). Serialization was fine (to binary, text, and XML), but deserialization of text and XML choke due to NaN and +-Inf. A workaround is to imbue the stream with a facet so that non-finite values are correctly parsed [1]. Boost.Math provides such a facet: boost::math::nonfinite_num_get (and ...put). See documentation at [2].
There is a nice posting at [3] showing how to use this facet and where to provide the Boost Serialization codecvt option.
---
[1] Note that NaN payloads are not necessarily restored exactly, but they will be restored to _some_ NaN, depending on the platform. (I believe this issue was a major factor in omission from Serialization.) See the facet documentation for more information.
[2] http://www.boost.org/doc/libs/1_50_0/libs/math/doc/sf_and_dist/html/math_toolkit/utils/fp_facets/intro.html
[3] http://stackoverflow.com/questions/22203496/deserialization-of-non-finite-floating-point-numbers-fails-even-with-appropriate
this has been discussed for years. It's not a problem of the serialization library per se. It's an effect of the fact that there is no standard/portable way for text based streams to represent various types of NaN s. no one has shown an interest is addressing this. So for now the best policy is to trap attempts so serialize Nan's to text base archives. I had thought we did that on serialization. Maybe you would like to investigate this in more detail
Robert Ramey