|
Boost : |
From: Paul A. Bristow (boost_at_[hidden])
Date: 2002-03-01 05:43:33
The following code fragment may be helpful in doing this.
using formulae by William Kahan
// http://http.cs.berkley.edu/~wkahan/ieee754status/ieee754.ps
double pi = 3.14159265358979323846264338327950288419716939937510; //
excessive digits!
{ // Test outputing values to a string and reading the string back in.
double spi; // to read back in and compare.
std::stringstream s;
s.precision(ceil(1 + std::numeric_limits<double>::digits * log10(2.)));
s << pi;
cout << s.str() << nl;
s >> spi;
assert (pi == spi);
cout << pi << tab << spi << endl;
} // pi test
This works as long as the value is not denormalised.
nextafter(0., 1.) = 4.9406564584124654e-324; which is denormalised, fails.
Paul
Dr Paul A Bristow, hetp Chromatography
Prizet Farmhouse
Kendal, Cumbria
LA8 8AB UK
+44 1539 561830
Mobile +44 7714 33 02 04
mailto:pbristow_at_[hidden]
> -----Original Message-----
> From: Fernando Cacciola [mailto:fcacciola_at_[hidden]]
> Sent: Wednesday, February 27, 2002 9:52 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] Re: Serialization (Persistence) library draft
> submission
>
>
>
> ----- Original Message -----
> From: "rameysb" <ramey_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Wednesday, February 27, 2002 6:41 PM
> Subject: [boost] Re: Serialization (Persistence) library draft submission
>
>
> > --- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
> > >
> > > ----- Original Message -----
> > > From: "Yitzhak Sapir" <ysapir_at_y...>
> > >
> > >
> > > > > 3) ar << * static_cast<const bus_stop *>(this);
> > > > >
> > > >
> > > > Implementing serialization with << and >> is nice, and it allows
> > you to
> > > > write code like this:
> > > >
> > > > socketstream << some_object;
> > > > cout << some_object;
> > > >
> > > > which looks very generic. In fact, you may not even need to know
> > which
> > > > type of stream you're serializing too. However, This is also
> > > > problematic. << and >> were not meant for serialization of
> > restorable
> > > > non-fielded data as far as I can see. That is, cout << 23 <<
> > 34; would
> > > > print 2334. Sent to a file and read back to an int, you'd
> > read "2334".
> > >
> > > There are much worse problems with operator>>() than that one, IMO.
> > How do
> > > you unserialize an object with no default constructor?
> > >
> > > -Dave
> >
> > 1) the class iarchive and oarchive are not derivations of streams.
> > They are implemented in terms of strings. the << operator for all
> > primitives are implemented to add a space after a number. Other
> > stream operations are not implemented by archives. so iarchive << 23
> > << 34 results in "23 34" being appended to the archive. There is are
> > special << and >> for strings.
> >
> Does this mean that everything is serialized as text?
>
> If I have a long double value, will it be serialized as a text string?
> In this case, is it guaranteed that the de-serialized value will be
> identical to the serialized one? (this requires a careful fp<->decimal
> conversion)
>
> Fernando Cacciola
> Sierra s.r.l.
> fcacciola_at_[hidden]
> www.gosierra.com
>
>
>
>
>
> Info: http://www.boost.org Send unsubscribe requests to:
<mailto:boost-unsubscribe_at_[hidden]>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk