143 lines
4.6 KiB
XML
143 lines
4.6 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.1//EN"
|
|
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
|
<section id="safe_numerics.checked_arithmetic">
|
|
<title>Checked Arithmetic</title>
|
|
|
|
<?dbhtml stop-chunking?>
|
|
|
|
<section>
|
|
<title>Description</title>
|
|
|
|
<para>Perform binary operations on arithmetic types. Return either a valid
|
|
result or an error code. Under no circumstances should an incorrect result
|
|
be returned.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Type requirements</title>
|
|
|
|
<para>All template parameters of the functions must model <link
|
|
linkend="safe_numerics.integer">Numeric</link> type requirements.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Complexity</title>
|
|
|
|
<para>Each function performs one and only one arithmetic operation.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Example of use</title>
|
|
|
|
<programlisting>#include <boost/numeric/safe_numerics/checked_default.hpp>
|
|
|
|
checked_result<int> r = checked::multiply<int>(24, 42);
|
|
</programlisting>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Notes</title>
|
|
|
|
<para>Some compilers have command line switches (e.g. -ftrapv) which
|
|
enable special behavior such that erroneous integer operations are
|
|
detected at run time. The library has been implemented in such a way that
|
|
these facilities are not used. It's possible they might be helpful in
|
|
particular environment. These could be be exploited by re-implementing
|
|
some functions in this library.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Synopsis</title>
|
|
|
|
<programlisting>// safe casting on primitive types
|
|
template<class R, class T>
|
|
checked_result<R> constexpr checked::cast(const T & t);
|
|
|
|
// safe addition on primitive types
|
|
template<class R>
|
|
checked_result<R> constexpr checked::add(const R & t, const R & u);
|
|
|
|
// safe subtraction on primitive types
|
|
template<class R>
|
|
checked_result<R> constexpr checked::subtract(const R & t, const R & u);
|
|
|
|
// safe multiplication on primitive types
|
|
template<class R>
|
|
checked_result<R> constexpr checked::multiply(const R & t, const R & u);
|
|
|
|
// safe division on primitive types
|
|
template<class R>
|
|
checked_result<R> constexpr checked::divide(const R & t, const R & u);
|
|
|
|
// safe modulus on primitive types
|
|
template<class R>
|
|
checked_result<R> constexpr checked::modulus(const R & t, const R & u);
|
|
|
|
// safe less than predicate on primitive types
|
|
template<class R>
|
|
bool constexpr checked::less_than(const R & t, const R & u);
|
|
|
|
// safe greater_than_equal predicate on primitive types
|
|
template<class R>
|
|
bool constexpr checked::greater_than_equal(const R & t, const R & u);
|
|
|
|
// safe greater_than predicate on primitive types
|
|
template<class R>
|
|
bool constexpr checked::greater_than(const R & t, const R & u);
|
|
|
|
// safe less_than_equal predicate on primitive types
|
|
template<class R>
|
|
bool constexpr checked::less_than_equal(const R & t, const R & u);
|
|
|
|
// safe equal predicate on primitive types
|
|
template<class R>
|
|
bool constexpr checked::equal(const R & t, const R & u);
|
|
|
|
// left shift
|
|
template<class R>
|
|
checked_result<R> constexpr checked::left_shift(const R & t, const R & u);
|
|
|
|
// right shift
|
|
template<class R>
|
|
checked_result<R> constexpr checked::right_shift(const R & t, const R & u);
|
|
|
|
// bitwise operations
|
|
template<class R>
|
|
checked_result<R> constexpr checked::bitwise_or(const R & t, const R & u);
|
|
|
|
template<class R>
|
|
checked_result<R> constexpr checked::bitwise_and(const R & t, const R & u);
|
|
|
|
template<class R>
|
|
checked_result<R> constexpr checked::bitwise_xor(const R & t, const R & u);
|
|
</programlisting>
|
|
</section>
|
|
|
|
<section>
|
|
<title>See Also</title>
|
|
|
|
<para><link
|
|
linkend="safenumerics.checked_result">checked_result<R></link></para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Header</title>
|
|
|
|
<para><ulink
|
|
url="../../include/boost/safe_numerics/checked_default.hpp"><code>#include
|
|
<boost/numeric/safe_numerics/checked_default.hpp>
|
|
</code></ulink></para>
|
|
|
|
<para><ulink
|
|
url="../../include/boost/safe_numerics/checked_integer.hpp"><code>#include
|
|
<boost/numeric/safe_numerics/checked_integer.hpp>
|
|
</code></ulink></para>
|
|
|
|
<para><ulink url="../../include/checked.hpp"><code/></ulink><ulink
|
|
url="../../include/boost/safe_numerics/checked_float.hpp"><code>#include
|
|
<boost/numeric/safe_numerics/checked_float.hpp>
|
|
</code></ulink></para>
|
|
</section>
|
|
</section>
|