rounding.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Rounding Rules for Conversions</title>
  5. <link rel="stylesheet" href="../../multiprecision.css" type="text/css">
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
  7. <link rel="home" href="../../index.html" title="Chapter&#160;1.&#160;Boost.Multiprecision">
  8. <link rel="up" href="../tut.html" title="Tutorial">
  9. <link rel="prev" href="import_export.html" title="Importing and Exporting Data to and from cpp_int and cpp_bin_float">
  10. <link rel="next" href="mixed.html" title="Mixed Precision Arithmetic">
  11. </head>
  12. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  13. <table cellpadding="2" width="100%"><tr>
  14. <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
  15. <td align="center"><a href="../../../../../../index.html">Home</a></td>
  16. <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
  17. <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
  18. <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
  19. <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
  20. </tr></table>
  21. <hr>
  22. <div class="spirit-nav">
  23. <a accesskey="p" href="import_export.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mixed.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section">
  26. <div class="titlepage"><div><div><h3 class="title">
  27. <a name="boost_multiprecision.tut.rounding"></a><a class="link" href="rounding.html" title="Rounding Rules for Conversions">Rounding Rules for
  28. Conversions</a>
  29. </h3></div></div></div>
  30. <p>
  31. As a general rule, all conversions between unrelated types are performed
  32. using basic arithmetic operations, therefore conversions are either exact,
  33. or follow the same rounding rules as arithmetic for the type in question.
  34. </p>
  35. <p>
  36. The following table summarises the situation for conversions from native
  37. types:
  38. </p>
  39. <div class="informaltable"><table class="table">
  40. <colgroup>
  41. <col>
  42. <col>
  43. </colgroup>
  44. <thead><tr>
  45. <th>
  46. <p>
  47. Backend
  48. </p>
  49. </th>
  50. <th>
  51. <p>
  52. Rounding Rules
  53. </p>
  54. </th>
  55. </tr></thead>
  56. <tbody>
  57. <tr>
  58. <td>
  59. <p>
  60. <a class="link" href="ints/cpp_int.html" title="cpp_int">cpp_int</a>
  61. </p>
  62. </td>
  63. <td>
  64. <p>
  65. Conversions from integer types are exact if the target has sufficient
  66. precision, otherwise they truncate to the first 2^MaxBits bits
  67. (modulo arithmetic). Conversions from floating-point types are
  68. truncating to the nearest integer.
  69. </p>
  70. </td>
  71. </tr>
  72. <tr>
  73. <td>
  74. <p>
  75. <a class="link" href="ints/gmp_int.html" title="gmp_int">gmp_int</a>
  76. </p>
  77. </td>
  78. <td>
  79. <p>
  80. Conversions are performed by the GMP library except for conversion
  81. from <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code>
  82. which is truncating.
  83. </p>
  84. </td>
  85. </tr>
  86. <tr>
  87. <td>
  88. <p>
  89. <a class="link" href="ints/tom_int.html" title="tom_int">tom_int</a>
  90. </p>
  91. </td>
  92. <td>
  93. <p>
  94. Conversions from floating-point types are truncating, all others
  95. are performed by libtommath and are exact.
  96. </p>
  97. </td>
  98. </tr>
  99. <tr>
  100. <td>
  101. <p>
  102. <a class="link" href="floats/gmp_float.html" title="gmp_float">gmp_float</a>
  103. </p>
  104. </td>
  105. <td>
  106. <p>
  107. Conversions are performed by the GMP library except for conversion
  108. from <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code>
  109. which should be exact provided the target type has as much precision
  110. as a <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code>.
  111. </p>
  112. </td>
  113. </tr>
  114. <tr>
  115. <td>
  116. <p>
  117. <a class="link" href="floats/mpfr_float.html" title="mpfr_float">mpfr_float</a>
  118. </p>
  119. </td>
  120. <td>
  121. <p>
  122. All conversions are performed by the underlying MPFR library.
  123. </p>
  124. </td>
  125. </tr>
  126. <tr>
  127. <td>
  128. <p>
  129. <a class="link" href="floats/cpp_dec_float.html" title="cpp_dec_float">cpp_dec_float</a>
  130. </p>
  131. </td>
  132. <td>
  133. <p>
  134. All conversions are performed using basic arithmetic operations
  135. and are truncating.
  136. </p>
  137. </td>
  138. </tr>
  139. <tr>
  140. <td>
  141. <p>
  142. <a class="link" href="rational/gmp_rational.html" title="gmp_rational">gmp_rational</a>
  143. </p>
  144. </td>
  145. <td>
  146. <p>
  147. See <a class="link" href="ints/gmp_int.html" title="gmp_int">gmp_int</a>
  148. </p>
  149. </td>
  150. </tr>
  151. <tr>
  152. <td>
  153. <p>
  154. <a class="link" href="rational/cpp_rational.html" title="cpp_rational">cpp_rational</a>
  155. </p>
  156. </td>
  157. <td>
  158. <p>
  159. See <a class="link" href="ints/cpp_int.html" title="cpp_int">cpp_int</a>
  160. </p>
  161. </td>
  162. </tr>
  163. <tr>
  164. <td>
  165. <p>
  166. <a class="link" href="rational/tommath_rational.html" title="tommath_rational">tommath_rational</a>
  167. </p>
  168. </td>
  169. <td>
  170. <p>
  171. See <a class="link" href="ints/tom_int.html" title="tom_int">tom_int</a>
  172. </p>
  173. </td>
  174. </tr>
  175. </tbody>
  176. </table></div>
  177. </div>
  178. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  179. <td align="left"></td>
  180. <td align="right"><div class="copyright-footer">Copyright &#169; 2002-2019 John Maddock
  181. and Christopher Kormanyos<p>
  182. Distributed under the Boost Software License, Version 1.0. (See accompanying
  183. file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
  184. </p>
  185. </div></td>
  186. </tr></table>
  187. <hr>
  188. <div class="spirit-nav">
  189. <a accesskey="p" href="import_export.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mixed.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
  190. </div>
  191. </body>
  192. </html>