checked.xml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.1//EN"
  3. "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
  4. <section id="safe_numerics.checked_arithmetic">
  5. <title>Checked Arithmetic</title>
  6. <?dbhtml stop-chunking?>
  7. <section>
  8. <title>Description</title>
  9. <para>Perform binary operations on arithmetic types. Return either a valid
  10. result or an error code. Under no circumstances should an incorrect result
  11. be returned.</para>
  12. </section>
  13. <section>
  14. <title>Type requirements</title>
  15. <para>All template parameters of the functions must model <link
  16. linkend="safe_numerics.integer">Numeric</link> type requirements.</para>
  17. </section>
  18. <section>
  19. <title>Complexity</title>
  20. <para>Each function performs one and only one arithmetic operation.</para>
  21. </section>
  22. <section>
  23. <title>Example of use</title>
  24. <programlisting>#include &lt;boost/numeric/safe_numerics/checked_default.hpp&gt;
  25. checked_result&lt;int&gt; r = checked::multiply&lt;int&gt;(24, 42);
  26. </programlisting>
  27. </section>
  28. <section>
  29. <title>Notes</title>
  30. <para>Some compilers have command line switches (e.g. -ftrapv) which
  31. enable special behavior such that erroneous integer operations are
  32. detected at run time. The library has been implemented in such a way that
  33. these facilities are not used. It's possible they might be helpful in
  34. particular environment. These could be be exploited by re-implementing
  35. some functions in this library.</para>
  36. </section>
  37. <section>
  38. <title>Synopsis</title>
  39. <programlisting>// safe casting on primitive types
  40. template&lt;class R, class T&gt;
  41. checked_result&lt;R&gt; constexpr checked::cast(const T &amp; t);
  42. // safe addition on primitive types
  43. template&lt;class R&gt;
  44. checked_result&lt;R&gt; constexpr checked::add(const R &amp; t, const R &amp; u);
  45. // safe subtraction on primitive types
  46. template&lt;class R&gt;
  47. checked_result&lt;R&gt; constexpr checked::subtract(const R &amp; t, const R &amp; u);
  48. // safe multiplication on primitive types
  49. template&lt;class R&gt;
  50. checked_result&lt;R&gt; constexpr checked::multiply(const R &amp; t, const R &amp; u);
  51. // safe division on primitive types
  52. template&lt;class R&gt;
  53. checked_result&lt;R&gt; constexpr checked::divide(const R &amp; t, const R &amp; u);
  54. // safe modulus on primitive types
  55. template&lt;class R&gt;
  56. checked_result&lt;R&gt; constexpr checked::modulus(const R &amp; t, const R &amp; u);
  57. // safe less than predicate on primitive types
  58. template&lt;class R&gt;
  59. bool constexpr checked::less_than(const R &amp; t, const R &amp; u);
  60. // safe greater_than_equal predicate on primitive types
  61. template&lt;class R&gt;
  62. bool constexpr checked::greater_than_equal(const R &amp; t, const R &amp; u);
  63. // safe greater_than predicate on primitive types
  64. template&lt;class R&gt;
  65. bool constexpr checked::greater_than(const R &amp; t, const R &amp; u);
  66. // safe less_than_equal predicate on primitive types
  67. template&lt;class R&gt;
  68. bool constexpr checked::less_than_equal(const R &amp; t, const R &amp; u);
  69. // safe equal predicate on primitive types
  70. template&lt;class R&gt;
  71. bool constexpr checked::equal(const R &amp; t, const R &amp; u);
  72. // left shift
  73. template&lt;class R&gt;
  74. checked_result&lt;R&gt; constexpr checked::left_shift(const R &amp; t, const R &amp; u);
  75. // right shift
  76. template&lt;class R&gt;
  77. checked_result&lt;R&gt; constexpr checked::right_shift(const R &amp; t, const R &amp; u);
  78. // bitwise operations
  79. template&lt;class R&gt;
  80. checked_result&lt;R&gt; constexpr checked::bitwise_or(const R &amp; t, const R &amp; u);
  81. template&lt;class R&gt;
  82. checked_result&lt;R&gt; constexpr checked::bitwise_and(const R &amp; t, const R &amp; u);
  83. template&lt;class R&gt;
  84. checked_result&lt;R&gt; constexpr checked::bitwise_xor(const R &amp; t, const R &amp; u);
  85. </programlisting>
  86. </section>
  87. <section>
  88. <title>See Also</title>
  89. <para><link
  90. linkend="safenumerics.checked_result">checked_result&lt;R&gt;</link></para>
  91. </section>
  92. <section>
  93. <title>Header</title>
  94. <para><ulink
  95. url="../../include/boost/safe_numerics/checked_default.hpp"><code>#include
  96. &lt;boost/numeric/safe_numerics/checked_default.hpp&gt;
  97. </code></ulink></para>
  98. <para><ulink
  99. url="../../include/boost/safe_numerics/checked_integer.hpp"><code>#include
  100. &lt;boost/numeric/safe_numerics/checked_integer.hpp&gt;
  101. </code></ulink></para>
  102. <para><ulink url="../../include/checked.hpp"><code/></ulink><ulink
  103. url="../../include/boost/safe_numerics/checked_float.hpp"><code>#include
  104. &lt;boost/numeric/safe_numerics/checked_float.hpp&gt;
  105. </code></ulink></para>
  106. </section>
  107. </section>