Boost logo

Boost :

From: Paul A Bristow (pbristow_at_[hidden])
Date: 2006-03-17 06:04:06


| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]] On Behalf Of John Maddock
| Sent: 16 March 2006 19:21
| To: Boost mailing list
| Subject: [boost] [serialisation] reading and writing reals
|
| Attached is a sketch of how reals can be serialised in hex
| notation, without
| data loss when round-tripping from binary-to-text-to-binary.

Quick work! And quite nice too.

(although to be pedantic, the formula for precision is still not what I
believe is correct, from Kahan

precision(2 + std::numeric_limits<double>::digits * 3010/10000)

but this is not the cause of the problem.
)

| 7) I've been unable to reproduce the original problem with
| native << and >>
| operators with either random value tests, or with sequential
| nextafter
| tests, unless I start with the specific value that caused all
| the fuss in
| the first place :-( Any ideas for better tests much appreciated.

A very brief look at this suggests that starting with values < 0.001 that
cause trouble.
So random testing may have trouble finding this.

Using nextafter always seems to produce 35% or 3 % of values wrong (by one
bit).

Starting with 0.0001

ends with

Original numerical value: 0.00010000000000001348
Contents of stream: 0.00010000000000001348
Deserialised value: 0.00010000000000001349
Deserialisation error!
Original numerical value: 0.0001000000000000135
Contents of stream: 0.0001000000000000135
Deserialised value: 0.00010000000000001349
Deserialisation error!
Original numerical value: 0.00010000000000001354
Contents of stream: 0.00010000000000001354
Deserialised value: 0.00010000000000001353
failed 450, out of 1000

I really don't have time to raise an long interrupt to look at this more
fully at the moment, but it smells like a bug (except that it has already
been deemed a 'feature' when I raised the same problem with the float
version).

So I suspect your proposal is a good workaround.

But I am concerned that we have a really good test for it, or that it is
provably correct, or better still both ;-))

With float, one can just about do a full test - takes all night.

But even with my new Dual Core AMD X2 ;-))

an exhaustive double won't finish before it is worn out :-((

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