mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-09 11:22:23 +00:00
150 lines
6.8 KiB
HTML
150 lines
6.8 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>Checked Integer Arithmetic</title>
|
|
<link rel="stylesheet" href="boostbook.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
|
|
<link rel="home" href="index.html" title="Safe Numerics">
|
|
<link rel="up" href="library_implementation.html" title="Library Implementation">
|
|
<link rel="prev" href="checked_result.html" title="checked_result<typename R>">
|
|
<link rel="next" href="interval.html" title="interval<typename R>">
|
|
</head>
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
<table cellpadding="2" width="100%"><tr>
|
|
<td valign="top"><img href="index.html" height="164px" src="pre-boost.jpg" alt="Library Documentation Index"></td>
|
|
<td><h2>Safe Numerics</h2></td>
|
|
</tr></table>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="checked_result.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="library_implementation.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="interval.html"><img src="images/next.png" alt="Next"></a>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="safe_numerics.checked_integer_arithmetic"></a>Checked Integer Arithmetic</h3></div></div></div>
|
|
<div class="toc"><dl>
|
|
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm473861327744">Synopsis</a></span></dt>
|
|
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm473861326032">Description</a></span></dt>
|
|
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm473861324592">Type requirements</a></span></dt>
|
|
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm473861322720">Complexity</a></span></dt>
|
|
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm473861321568">Header</a></span></dt>
|
|
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm473861319936">Example of use</a></span></dt>
|
|
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm473861317680">Notes</a></span></dt>
|
|
<dt><span class="section"><a href="checked_integer_arithmetic.html#idm473861316528">See Also</a></span></dt>
|
|
</dl></div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861327744"></a>Synopsis</h4></div></div></div>
|
|
<pre class="programlisting">// safe casting on primitive types
|
|
template<class R, class T>
|
|
constexpr checked_result<R>
|
|
checked::cast(const T & t);
|
|
|
|
// safe addition on primitive types
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::add(const T & t, const U & u);
|
|
|
|
// safe subtraction on primitive types
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::subtract(const T & t, const U & u);
|
|
|
|
// safe multiplication on primitive types
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::multiply(const T & t, const U & u);
|
|
|
|
// safe division on unsafe types
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::divide(const T & t, const U & u);
|
|
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::divide_automatic(const T & t, const U & u);
|
|
|
|
// safe modulus on unsafe types
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::modulus(const T & t, const U & u);
|
|
|
|
// left shift
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::left_shift(const T & t, const U & u);
|
|
|
|
// right shift
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::right_shift(const T & t, const U & u);
|
|
|
|
// bitwise operations
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::bitwise_or(const T & t, const U & u);
|
|
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::bitwise_and(const T & t, const U & u);
|
|
|
|
template<class R, class T, class U>
|
|
constexpr checked_result<R>
|
|
checked::bitwise_xor(const T & t, const U & u);
|
|
</pre>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861326032"></a>Description</h4></div></div></div>
|
|
<p>Perform binary operations on arithmetic types. Return either a valid
|
|
result or an error code. Under no circumstances should an incorrect result
|
|
be returned.</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861324592"></a>Type requirements</h4></div></div></div>
|
|
<p>All template parameters of the functions must model <a class="link" href="integer.html" title="Integer<T>">Integer</a> type requirements.</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861322720"></a>Complexity</h4></div></div></div>
|
|
<p>Each function performs one and only one arithmetic operation</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861321568"></a>Header</h4></div></div></div>
|
|
<p><code class="computeroutput">#include "checked.hpp" </code></p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861319936"></a>Example of use</h4></div></div></div>
|
|
<p>[A code fragment that illustrates how to use the function.]</p>
|
|
<pre class="programlisting">#include "checked.hpp"
|
|
|
|
checked_result<result_base_type> r = checked::multiply<int>(24, 42);
|
|
</pre>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861317680"></a>Notes</h4></div></div></div>
|
|
<p>Footnotes (if any) that are referred to by other parts of the
|
|
page.</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861316528"></a>See Also</h4></div></div></div>
|
|
<p><a class="link" href="checked_result.html" title="checked_result<typename R>">checked_result<typename
|
|
R></a></p>
|
|
</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 © 2012 Robert Ramey<p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">Subject to Boost
|
|
Software License</a></p>
|
|
</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="checked_result.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="library_implementation.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="interval.html"><img src="images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|