Files
safe_numerics/doc/boostbook/numeric_concept.xml
Robert Ramey 63dd89210e Enabled Boost Book syntax highlighting
improved TOC and chunking.  This is complicated by the fact we that we desire different depths.
put copies of boost logo in subdirectories
2016-02-07 14:38:06 -08:00

479 lines
11 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.numeric">
<title>Numeric&lt;T&gt;</title>
<?dbhtml stop-chunking?>
<section id="safe_numerics.numeric.description">
<title>Description</title>
<para>A type is Numeric if it has the properties of a number.</para>
<para>More specifically, a type T is Numeric if there exists
specialization of <code>std::numeric_limits&lt;T&gt;</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>is_integral</code> and <code>is_arithmetic</code>. These
latter fulfill the requirement of the concept Numeric. But there are types
T which fulfill this concept for which <code>is_arithmetic&lt;T&gt;::value
== false</code>. For example see
<code>safe_signed_integer&lt;int&gt;</code>.</para>
</section>
<section>
<title>Notation</title>
<informaltable>
<tgroup cols="2" colsep="1" rowsep="1">
<colspec align="left"/>
<colspec align="left" colwidth="3*"/>
<tbody>
<row>
<entry><code>T, U, V</code></entry>
<entry>A type that is a model of the Numeric</entry>
</row>
<row>
<entry><code>t, u</code></entry>
<entry>An object of type modeling Numeric</entry>
</row>
<row>
<entry><code>os</code></entry>
<entry>An object of type std::base_ostreami</entry>
</row>
<row>
<entry><code>is</code></entry>
<entry>An object of type std::base_istream</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</section>
<section>
<title>Associated Types</title>
<informaltable>
<tgroup cols="2">
<colspec align="left"/>
<colspec align="left" colwidth="3*"/>
<tbody>
<row>
<entry><code>std::numeric_limits&lt;T&gt;</code></entry>
<entry>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.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</section>
<section>
<title>Valid Expressions</title>
<para>In addition to the expressions defined in <ulink
url="http://www.sgi.com/tech/stl/Assignable.html">Assignable</ulink> the
following expressions must be valid. Any operations which result in
integers which cannot be represented as some Numeric type will throw an
exception.<table>
<title>General</title>
<tgroup cols="2">
<colspec align="left" colwidth="406*"/>
<colspec align="left" colwidth="594*"/>
<thead>
<row>
<entry align="left">Expression</entry>
<entry>Return Value</entry>
</row>
</thead>
<tbody>
<row>
<entry><code>std::numeric_limits&lt;T&gt;.is_bounded
</code></entry>
<entry>true</entry>
</row>
<row>
<entry><code>std::numeric_limits&lt;T&gt;.is_specialized
</code></entry>
<entry>true</entry>
</row>
<row>
<entry><code><entry>os &lt;&lt; T</entry></code></entry>
<entry>os &amp;i</entry>
</row>
<row>
<entry><code><entry>is &gt;&gt; T</entry></code></entry>
<entry>is &amp;</entry>
</row>
</tbody>
</tgroup>
</table></para>
<table>
<title>Unary Operators</title>
<tgroup cols="3">
<colspec align="left"/>
<colspec align="left"/>
<colspec align="left" colwidth="3*"/>
<thead>
<row>
<entry align="left">Expression</entry>
<entry>Return Type</entry>
<entry>Semantics</entry>
</row>
</thead>
<tbody>
<row>
<entry><code>-t</code></entry>
<entry>T</entry>
<entry>Invert sign</entry>
</row>
<row>
<entry><code>+t</code></entry>
<entry>T</entry>
<entry>unary plus - a no op</entry>
</row>
<row>
<entry><code>t--</code></entry>
<entry>T</entry>
<entry>post decrement</entry>
</row>
<row>
<entry><code>t++</code></entry>
<entry>T</entry>
<entry>post increment</entry>
</row>
<row>
<entry><code>--t</code></entry>
<entry>T</entry>
<entry>pre decrement</entry>
</row>
<row>
<entry><code>++t</code></entry>
<entry>T</entry>
<entry>pre increment</entry>
</row>
<row>
<entry><code>~</code></entry>
<entry>T</entry>
<entry>complement</entry>
</row>
</tbody>
</tgroup>
</table>
<table>
<title>Binary Operators</title>
<tgroup cols="3">
<colspec align="left"/>
<colspec align="left"/>
<colspec align="left" colwidth="3*"/>
<thead>
<row>
<entry align="left">Expression</entry>
<entry>Return Type</entry>
<entry>Semantics</entry>
</row>
</thead>
<tbody>
<row>
<entry><code>t - u</code></entry>
<entry>V</entry>
<entry>subtract u from t</entry>
</row>
<row>
<entry><code>t + u</code></entry>
<entry>V</entry>
<entry>add u to t</entry>
</row>
<row>
<entry><code>t * u</code></entry>
<entry>V</entry>
<entry>multiply t by u</entry>
</row>
<row>
<entry><code>t / u</code></entry>
<entry>T</entry>
<entry>divide t by u</entry>
</row>
<row>
<entry><code>t % u</code></entry>
<entry>T</entry>
<entry>t modulus u</entry>
</row>
<row>
<entry><code>t &lt;&lt; u</code></entry>
<entry>T</entry>
<entry>shift t left u bits</entry>
</row>
<row>
<entry><code>t &gt;&gt; u</code></entry>
<entry>T</entry>
<entry>shift t right by u bits</entry>
</row>
<row>
<entry><code>t &lt; u</code></entry>
<entry>bool</entry>
<entry>true if t less than u, false otherwise</entry>
</row>
<row>
<entry><code>t &lt;= u</code></entry>
<entry>bool</entry>
<entry>true if t less than or equal to u, false otherwise</entry>
</row>
<row>
<entry><code>t &gt; u</code></entry>
<entry>bool</entry>
<entry>true if t greater than u, false otherwise</entry>
</row>
<row>
<entry><code>t &gt;= u</code></entry>
<entry>bool</entry>
<entry>true if t greater than or equal to u, false
otherwise</entry>
</row>
<row>
<entry><code>t == u</code></entry>
<entry>bool</entry>
<entry>true if t equal to u, false otherwise</entry>
</row>
<row>
<entry><code>t != u</code></entry>
<entry>bool</entry>
<entry>true if t not equal to u, false otherwise</entry>
</row>
<row>
<entry><code>t &amp; u</code></entry>
<entry>V</entry>
<entry>and of t and u padded out max # bits in t, u</entry>
</row>
<row>
<entry><code>t | u</code></entry>
<entry>V</entry>
<entry>or of t and u padded out max # bits in t, u</entry>
</row>
<row>
<entry><code>t ^ u</code></entry>
<entry>V</entry>
<entry>exclusive or of t and u padded out max # bits in t,
u</entry>
</row>
<row>
<entry><code>t = u</code></entry>
<entry><code>T</code></entry>
<entry>assign value of u to t</entry>
</row>
<row>
<entry><code>t += u</code></entry>
<entry><code>T</code></entry>
<entry>add u to t and assign to t</entry>
</row>
<row>
<entry><code>t -= u</code></entry>
<entry><code>T</code></entry>
<entry>subtract u from t and assign to t</entry>
</row>
<row>
<entry><code>t *= u</code></entry>
<entry><code>T</code></entry>
<entry>multiply t by u and assign to t</entry>
</row>
<row>
<entry><code>t /= u</code></entry>
<entry><code>T</code></entry>
<entry>divide t by u and assign to t</entry>
</row>
<row>
<entry><code>t &amp;= u</code></entry>
<entry><code>T</code></entry>
<entry>and t with u and assign to t</entry>
</row>
<row>
<entry><code>t &lt;&lt;= u</code></entry>
<entry>T</entry>
<entry>left shift the value of t by u bits</entry>
</row>
<row>
<entry><code>t &gt;&gt;= u</code></entry>
<entry>T</entry>
<entry>right shift the value of t by u bits</entry>
</row>
<row>
<entry><code>t &amp;= u</code></entry>
<entry>T</entry>
<entry>and the value of t with u and assign to t</entry>
</row>
<row>
<entry><code>t |= u</code></entry>
<entry>T</entry>
<entry>or the value of t with u and assign to t</entry>
</row>
<row>
<entry><code>t ^= u</code></entry>
<entry>T</entry>
<entry>exclusive or the value of t with u and assign to t</entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section>
<title>Header</title>
<para><ulink url="../../include/concept/numeric.hpp"><code>#include
&lt;safe_numerics/include/concepts/numeric.hpp&gt; </code></ulink></para>
</section>
<section>
<title>Models</title>
<para><code>int, safe_signed_integer&lt;int&gt;,
safe_signed_range&lt;int&gt;, etc.</code></para>
<para>The definition of this concept</para>
</section>
</section>