| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>Logging floating point type numbers</title> |
| <link rel="stylesheet" href="../../../../style/style.css" type="text/css"> |
| <meta name="generator" content="DocBook XSL Stylesheets V1.74.0"> |
| <link rel="home" href="../../../index.html" title="Boost Test Library"> |
| <link rel="up" href="test-log.html" title="Test log output"> |
| <link rel="prev" href="BOOST_TEST_PASSPOINT.html" title="BOOST_TEST_PASSPOINT"> |
| <link rel="next" href="log-hr-format.html" title="Human readable log output format"> |
| <script language="JavaScript1.2" src="../../../../js/boost-test.js"></script> |
| </head> |
| <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| <table width="100%"><tr> |
| <td width="10%"><a href="../../../index.html"><img alt="Home" width="229" height="61" border="0" src="../../../../../../../libs/test/docbook/img/boost.test.logo.png"></a></td> |
| <td valign="middle" align="left"> > <a href="../../../utf.html">The Unit Test Framework</a> > <a href="../../user-guide.html">User's guide</a><a href="../../testing-tools.html"> |
| > |
| </a><a href="../test-output.html">Test Output </a><a href="../runtime-config.html"> |
| > |
| </a><a href="test-log.html">Test log</a><a href="results-report.html"> |
| > |
| </a><b>Logging floating point type numbers</b> |
| </td> |
| <td><div class="spirit-nav"> |
| <a href="BOOST_TEST_PASSPOINT.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a href="log-hr-format.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a> |
| </div></td> |
| </tr></table> |
| <hr> |
| <div class="section" lang="en"> |
| <div class="titlepage"><div><div><h6 class="title"> |
| <a name="utf.user-guide.test-output.log.FPT"></a>Logging floating point type numbers</h6></div></div></div> |
| <p class="first-line-indented"> |
| It may appear that floating-point numbers are displayed by the <acronym class="acronym">UTF</acronym> with an excessive number of decimal digits. |
| However the number of digits shown is chosen to avoid apparently nonsensical displays like <code class="computeroutput">[1.00000 != 1.00000]</code> |
| when comparing exactly unity against a value which is increased by just one least significant binary digit using |
| the default precision for float of just 6 decimal digits, given by |
| <code class="computeroutput">std::numeric_limits</code><float>::digits10. The function used for the number of decimal |
| digits displayed is that proposed for a future C++ Standard, |
| <a href="http://www2.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf" target="_top">A Proposal to add a max |
| significant decimal digits value</a>, to be called <code class="computeroutput">std::numeric_limits</code>::max_digits10();. |
| For 32-bit floats, 9 decimal digits are needed to ensure a single bit change produces a different decimal digit |
| string. |
| </p> |
| <p class="first-line-indented"> |
| So a much more helpful display using 9 decimal digits is thus: |
| <code class="computeroutput">[1.00000000 != 1.00000012]</code> showing that the two values are in fact different. |
| </p> |
| <p class="first-line-indented"> |
| For <acronym class="acronym">IEEE754</acronym> 32-bit float values - 9 decimal digits are shown. For 64-bit <acronym class="acronym">IEEE754</acronym> double - 17 decimal digits. For |
| <acronym class="acronym">IEEE754</acronym> extended long double using 80-bit - 21 decimal digits. For <acronym class="acronym">IEEE754</acronym> quadruple long double 128-bit, and Sparc |
| extended long double 128-bit - 36 decimal digits. For floating-point types, a convenient formula to calculate |
| max_digits10 is: 2 + <code class="computeroutput">std::numeric_limits</code><FPT>::digits * 3010/10000; |
| </p> |
| <div class="note"><table border="0" summary="Note"> |
| <tr> |
| <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/html/images/note.png"></td> |
| <th align="left">Note</th> |
| </tr> |
| <tr><td align="left" valign="top"><p> |
| Note that a user defined floating point type UDFPT must define |
| <code class="computeroutput">std::numeric_limits</code><UDFPT>::is_specialized = true and provide an appropriate value |
| for <code class="computeroutput">std::numeric_limits</code><UDFPT>::digits, the number of bits used for the significand |
| or mantissa. For example, for the Sparc extended long double 128, 113 bits are used for the significand (one of |
| which is implicit). |
| </p></td></tr> |
| </table></div> |
| </div> |
| <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> |
| <td align="left"></td> |
| <td align="right"><div class="copyright-footer">Copyright © 2001-2007 Gennadiy Rozental</div></td> |
| </tr></table> |
| <hr> |
| <div class="spirit-nav"> |
| <a accesskey="p" href="BOOST_TEST_PASSPOINT.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="test-log.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="log-hr-format.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a> |
| </div> |
| </body> |
| </html> |