|
Boost Users : |
Subject: Re: [Boost-users] boost serialization stream error question
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2010-01-31 20:39:52
On Sun, Jan 31, 2010 at 6:11 PM, Robert Ramey <ramey_at_[hidden]> wrote:
> OvermindDL1 wrote:
>> On Sun, Jan 31, 2010 at 10:34 AM, Robert Ramey <ramey_at_[hidden]> wrote:
>>>> The problem is caused by double values less than DBL_MIN.
>>>> Apparently, streaming such values in causes the input stream
>>>> fail_bit to be set, which causes the serialization lib to throw an
>>>> exception.
>>>
>>> The standard stream library writes out NaN values as text, but
>>> cannot read them.
>>>
>>> It shows up in various places besides the serialization library -
>>> e.g. lexical_cast.
>>>
>>> Work has been done on this. I believe that there is code in vault
>>> which deals with this.
>>
>> Why not just memcpy the double into the stream? (or bitcast it to long
>> long or so?)
>
> text and xml archives are meant to be portable. Â This would conflict
> with that requirement. Â Then there is the fact that putting binary data
> into the text stream might create some conflicts depending on the
> characterset etc. Â In general, one cannot put binary data into a text
> stream and be able to count on getting it back.
>
> So here are a couple of options in order of my personal preference.
>
> a) Just avoid saving and restoring NaN's. Â They just waste space
> in the archive anyway. There a number ways to do this.
> b) find the fixup for floating point stream in either the vault and/or
> sand box and install that.
> b) wrap the double in a binary_wrapper and serialize that. Â This
> would also break portability.
What about for text archives print/read it out in the completely
portable C99 Hex floating point constant? It encodes all possible
floating point values with no loss (including NaNs and such). It is
basically just a hex representation of the memory, see the C99 hex
floating point standard for how it works.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net