Boost logo

Boost :

From: Paul A Bristow (pbristow_at_[hidden])
Date: 2006-02-09 17:19:47


Some of you have noted (with displeasure) the ugly display of floating point
values from

BOOST_CHECK_CLOSE

for example

difference between +1e-6{9.9999999999999995e-007} and
1e-5{1.0000000000000001e-005} exceeds 2.22045e-018%

The number of decimal digits used is enough to show all that can be
significant.

For 64-bit doubles it is 17 decimal digits, (for 32-bit float 9) and for
long double, quad_float even more.

This is undoubtedly ugly, but has the virtue that it avoids apparently
nonsensical displays like

1.000000 != 1.000000

when comparing 1.f, with the next after, one least significant bit above
1.00000012f,

which is what you get if the standard 6 decimal digits for float is used.

It has another great virtue - it highlights the limitations of storing
decimal representations in binary.

There are smarter algorithms for display (which Gennadiy is considering),
but IMO this is the C++ standard way of doing these things and I suggest
that this is the Right Thing To Do in this case.

Are there any dissenting views?

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