mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-12 12:22:16 +00:00
364 lines
13 KiB
HTML
364 lines
13 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>Numeric<T></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="concepts.html" title="Concepts">
|
|
<link rel="prev" href="concepts.html" title="Concepts">
|
|
<link rel="next" href="types.html" title="Types">
|
|
</head>
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
<table cellpadding="2" width="100%"><tr>
|
|
<td valign="top"><img alt="pre-boost" width="30%" height="30%" src="pre-boost.jpg"></td>
|
|
<td align="center"><a href="../../index.html">Home</a></td>
|
|
<td align="center"><a href="http://www.boost.org/doc/libs">Libraries</a></td>
|
|
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
|
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
|
<td align="center"><a href="../../more/index.htm">More</a></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="concepts.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="concepts.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="types.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.numeric"></a>Numeric<T></h3></div></div></div>
|
|
<div class="toc"><dl>
|
|
<dt><span class="section"><a href="numeric.html#id699580">Description</a></span></dt>
|
|
<dt><span class="section"><a href="numeric.html#id741994">Notation</a></span></dt>
|
|
<dt><span class="section"><a href="numeric.html#id742071">Associated Types</a></span></dt>
|
|
<dt><span class="section"><a href="numeric.html#id742130">Valid Expressions</a></span></dt>
|
|
<dt><span class="section"><a href="numeric.html#id753392">Header</a></span></dt>
|
|
<dt><span class="section"><a href="numeric.html#id753413">Models</a></span></dt>
|
|
</dl></div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="id699580"></a>Description</h4></div></div></div>
|
|
<p>A type is Numeric if it has the properties of a number.</p>
|
|
<p>More specifically, a type T is Numeric if there exists
|
|
specialization of <code class="computeroutput">std::numeric_limits<T></code>. See the
|
|
documentation for standard library class numeric_limits. The standard
|
|
library includes such specializations for all the primitive numeric types.
|
|
Note that this concept is distinct from the C++ standard library type
|
|
traits <code class="computeroutput">is_integral</code> and <code class="computeroutput">is_arithmetic</code>. These
|
|
latter fullfill the requirement of the concept Numeric. But there are
|
|
types T which fullfill this concept for which
|
|
<code class="computeroutput">is_arithmetic<T>::value == false</code>. For example see
|
|
<code class="computeroutput">safe_signed_integer<int></code>.</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="id741994"></a>Notation</h4></div></div></div>
|
|
<div class="table">
|
|
<a name="id742000"></a><p class="title"><b>Table 1. Notation</b></p>
|
|
<div class="table-contents"><table class="table" summary="Notation">
|
|
<colgroup>
|
|
<col align="left">
|
|
<col align="left">
|
|
</colgroup>
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">T, U, V</code></td>
|
|
<td align="left">A type that is a model of the Numeric</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t, u, v</code></td>
|
|
<td align="left">An object of type modeling Numeric</td>
|
|
</tr>
|
|
</tbody>
|
|
</table></div>
|
|
</div>
|
|
<br class="table-break">
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="id742071"></a>Associated Types</h4></div></div></div>
|
|
<div class="table">
|
|
<a name="id742077"></a><p class="title"><b>Table 2. Associated Types</b></p>
|
|
<div class="table-contents"><table class="table" summary="Associated Types">
|
|
<colgroup>
|
|
<col align="left">
|
|
<col align="left">
|
|
</colgroup>
|
|
<tbody><tr>
|
|
<td align="left"><code class="computeroutput">std::numeric_limits<T></code></td>
|
|
<td align="left">The numeric_limits class template provides a C++ program
|
|
with information about various properties of the implementation’s
|
|
representation of the arithmetic types. See C++ standard
|
|
18.3.2.2.</td>
|
|
</tr></tbody>
|
|
</table></div>
|
|
</div>
|
|
<br class="table-break">
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="id742130"></a>Valid Expressions</h4></div></div></div>
|
|
<p>In addition to the expressions defined in <a href="http://www.sgi.com/tech/stl/Assignable.html" target="_top">Assignable</a> the
|
|
following expressions must be valid.</p>
|
|
<p>Any operations which result in integers which cannot be represented
|
|
as some Numeric type will throw an exception.</p>
|
|
<div class="table">
|
|
<a name="id742150"></a><p class="title"><b>Table 3. General</b></p>
|
|
<div class="table-contents"><table class="table" summary="General">
|
|
<colgroup>
|
|
<col align="left">
|
|
<col align="left">
|
|
</colgroup>
|
|
<thead><tr>
|
|
<th align="left">Expression</th>
|
|
<th align="left">Return Value</th>
|
|
</tr></thead>
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">std::numeric_limits<T>.is_bounded
|
|
</code></td>
|
|
<td align="left">true</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">std::numeric_limits<T>.is_integer</code></td>
|
|
<td align="left">true</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">std::numeric_limits<T>.is_specialized
|
|
</code></td>
|
|
<td align="left">true</td>
|
|
</tr>
|
|
</tbody>
|
|
</table></div>
|
|
</div>
|
|
<p><br class="table-break"></p>
|
|
<div class="table">
|
|
<a name="id742245"></a><p class="title"><b>Table 4. Unary Operators</b></p>
|
|
<div class="table-contents"><table class="table" summary="Unary Operators">
|
|
<colgroup>
|
|
<col align="left">
|
|
<col align="left">
|
|
<col align="left">
|
|
</colgroup>
|
|
<thead><tr>
|
|
<th align="left">Expression</th>
|
|
<th align="left">Return Type</th>
|
|
<th align="left">Semantics</th>
|
|
</tr></thead>
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">-t</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">Invert sign</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">+t</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">unary plus - a no op</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t--</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">post decrement</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t++</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">post increment</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">--t</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">predecrement</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">++t</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">preincrement</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">~</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">complement</td>
|
|
</tr>
|
|
</tbody>
|
|
</table></div>
|
|
</div>
|
|
<br class="table-break"><div class="table">
|
|
<a name="id697780"></a><p class="title"><b>Table 5. Binary Operators</b></p>
|
|
<div class="table-contents"><table class="table" summary="Binary Operators">
|
|
<colgroup>
|
|
<col align="left">
|
|
<col align="left">
|
|
<col align="left">
|
|
</colgroup>
|
|
<thead><tr>
|
|
<th align="left">Expression</th>
|
|
<th align="left">Return Type</th>
|
|
<th align="left">Semantics</th>
|
|
</tr></thead>
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t - u</code></td>
|
|
<td align="left">V</td>
|
|
<td align="left">Invert sign</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t + u</code></td>
|
|
<td align="left">V</td>
|
|
<td align="left">unary plus - a no op</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t * u</code></td>
|
|
<td align="left">V</td>
|
|
<td align="left">multiply t by u</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t / u</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">divide t by u</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t % u</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">t modulus u</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t << u</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">shift t left u bits</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t >> u</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">shift t right by ubits</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t < u</code></td>
|
|
<td align="left">bool</td>
|
|
<td align="left">true if t less than u, false otherwise</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t <= u</code></td>
|
|
<td align="left">bool</td>
|
|
<td align="left">true if t less than or equal to u, false otherwise</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t > u</code></td>
|
|
<td align="left">bool</td>
|
|
<td align="left">true if t greater than u, false otherwise</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t >= u</code></td>
|
|
<td align="left">bool</td>
|
|
<td align="left">true if t greathan or equal to u, false otherwise</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t == u</code></td>
|
|
<td align="left">bool</td>
|
|
<td align="left">true if t equal to u, false otherwise</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t != u</code></td>
|
|
<td align="left">bool</td>
|
|
<td align="left">true if t not equal to u, false otherwise</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t & u</code></td>
|
|
<td align="left">V</td>
|
|
<td align="left">and of t and u padded out max # bits in t, u</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t | u</code></td>
|
|
<td align="left">V</td>
|
|
<td align="left">or of t and u padded out max # bits in t, u</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t ^ u</code></td>
|
|
<td align="left">V</td>
|
|
<td align="left">exclusive or of t and u padded out max # bits in t,
|
|
u</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t = u</code></td>
|
|
<td align="left"><code class="computeroutput">T</code></td>
|
|
<td align="left">assign value of u to t</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t += u</code></td>
|
|
<td align="left"><code class="computeroutput">T</code></td>
|
|
<td align="left">add u to t and assign to t</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t -= u</code></td>
|
|
<td align="left"><code class="computeroutput">T</code></td>
|
|
<td align="left">subtract u from t and assign to t</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t *= u</code></td>
|
|
<td align="left"><code class="computeroutput">T</code></td>
|
|
<td align="left">multiply t by u and assign to t</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t /= u</code></td>
|
|
<td align="left"><code class="computeroutput">T</code></td>
|
|
<td align="left">divide t by u and assign to t</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t &= u</code></td>
|
|
<td align="left"><code class="computeroutput">T</code></td>
|
|
<td align="left">and t with u and assign to t</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t <<= u</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">left shift the value of t by u bits</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t >>= u</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">right shift the value of t by u bits</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t &= u</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">and the value of t with u and assign to t</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t |= u</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">or the value of t with u and assign to t</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t ^= u</code></td>
|
|
<td align="left">T</td>
|
|
<td align="left">exclusive or the value of t with u and assign to t</td>
|
|
</tr>
|
|
</tbody>
|
|
</table></div>
|
|
</div>
|
|
<br class="table-break">
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="id753392"></a>Header</h4></div></div></div>
|
|
<p><a href="../../include/concept/numeric.hpp" target="_top"><code class="computeroutput">#include
|
|
<safe_numerics/include/concepts/numeric.hpp> </code></a></p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="id753413"></a>Models</h4></div></div></div>
|
|
<p><code class="computeroutput">int, safe_signed_integer<int>,
|
|
safe_signed_range<int>, etc.</code></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="???" target="_top">Subject to Boost Software License</a></p>
|
|
</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="concepts.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="concepts.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="types.html"><img src="images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|