Boost test - displaying float point numbers

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@hetp.u-net.com http://www.hetp.u-net.com/index.html http://www.hetp.u-net.com/Paul%20A%20Bristow%20info.html

At 15:19 2006-02-09, Paul A Bristow wrote:
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.
I don't see where you're getting your # of digits my calculations show that it's around 14 for 64bit floating and around 7 for 32bit numeric_limits<>::digits10 shows 6 for float, 15 for double on vc8
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@hetp.u-net.com http://www.hetp.u-net.com/index.html http://www.hetp.u-net.com/Paul%20A%20Bristow%20info.html
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"

I don't see where you're getting your # of digits my calculations show that it's around 14 for 64bit floating and around 7 for 32bit numeric_limits<>::digits10 shows 6 for float, 15 for double on vc8
Those are the numbers of decimal digits that can be stored without loss in binary form, the number of decimal digits needed to represent a binary number without loss is somewhat higher (about 2 digits higher will usually suffice). John.

| -----Original Message----- | From: boost-bounces@lists.boost.org | [mailto:boost-bounces@lists.boost.org] On Behalf Of Victor A. | Wagner Jr. | Sent: 10 February 2006 06:08 | To: boost@lists.boost.org; boost@lists.boost.org | Subject: Re: [boost] Boost test - displaying float point numbers | | At 15:19 2006-02-09, Paul A Bristow wrote: | >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. | | I don't see where you're getting your # of digits | my calculations show that it's around 14 for 64bit floating and | around 7 for 32bit | numeric_limits<>::digits10 shows 6 for float, 15 for double on vc8
From formula given by Kahan, inventor of IEEE754, so he should know!
http://http.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF Page 4 and this was proposed http://www2.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf and found favour with WG14 so may well be part of TR2. Note that the number of digits required to show all possibly significant digits which I have called max_digits10 (and and as max significant digits MACROs for C N1151 to WG14 FLT_DIG 6, FLT_MAXDIG10 9 DBL_DIG 15, DBL_MAXDIG10 17 LDBL_DIG 19, LDBL_MAXDIG10 21 is 2 or 3 more than numeric_limits<>::digits10 which is effectively the numerb that are guranteed correct - after being rounded. 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@hetp.u-net.com http://www.hetp.u-net.com/index.html http://www.hetp.u-net.com/Paul%20A%20Bristow%20info.html
participants (3)
-
John Maddock
-
Paul A Bristow
-
Victor A. Wagner Jr.