Boost logo

Boost :

From: Paul A Bristow (pbristow_at_[hidden])
Date: 2006-03-15 15:15:10


 

| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]] On Behalf Of Janek Kozicki
| Sent: 15 March 2006 18:47
| To: boost_at_[hidden]
| Subject: Re: [boost] [serialization]
| Serialisation/deserialisation offloating-point values
|
| Paul A Bristow said: (by the date of Wed, 15 Mar 2006
| 15:23:50 -0000)
|
| > | > | This suggests that it is a broken feature of Microsoft's
| > | > | operator>> for doubles read from filestreams.
| > |
| > |
| > | why not just read the string, ans use
| boost::lexical_cast<double> ?
| > |
| > | --
| > | Janek Kozicki
| >
| > I fear that lexical_cast uses the same method of reading
| from a stringstream
| > :-((
| >
| > And that our testing of lexical_cast is insufficient to catch it.
| >
| > Some very rough tests of lexical_cast suggest that several
| percent of not
| > very random double values fail to loopback ( 1 bit wrong),
| but I don't have
| > time to work on this at present.
|
| but if during saving lexical_cast<string>(some_double_value) is used
| IMHO no data should be lost at all. operator<< for string
| cannot make a
| mistake. Also operator>> for string shouldn't make a mistake,
| otherwise
| copying around textual data with << and >> should lead to
| data corruption.
| (think copying text file using microsoft's operators << and >> )
|
| bear in mind that lexical_cast<string>(foo) converts double to string
| without any data loss (that's the exact purpose of lexical_cast). Then
| later if this data is treated as string then it's not possible to loss
| any information (otherwise we have a plain corruption of
| textual data).
|
| so during save you convert double to string, then save.
| when you load it - you load a string, then convert it to double.

                std::stringstream stream;
                double num;
                stream << std::setprecision(3 +
std::numeric_limits<double>::digits * 3030/10000);
                stream << orig_value;
                stream >> num; // <<<<<<<<<< This is where I believe it
goes wrong, sometimes, by one 1 bit :-((

so orig_value != num.

Or am I misunderstanding your suggestion?

Paul
 

-- 
Paul A Bristow
Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB
Phone and SMS text +44 1539 561830, Mobile and SMS text +44 7714 330204
mailto: pbristow_at_[hidden]  http://www.hetp.u-net.com/index.html
http://www.hetp.u-net.com/Paul%20A%20Bristow%20info.html

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk