Files
safe_numerics/doc/boostbook/numeric_concept.xml

393 lines
9.1 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 a
specialization of <code>std::numeric_limits&lt;T&gt;</code>. See the
documentation for the standard library class <code>numeric_limits</code>.
The standard library includes such specializations for all the built-in
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 Numeric</entry>
</row>
<row>
<entry><code>t, u</code></entry>
<entry>An object of a type modeling Numeric</entry>
</row>
<row>
<entry><code>os</code></entry>
<entry>An object of type std::base_ostream</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 or false</entry>
</row>
<row>
<entry><code>std::numeric_limits&lt;T&gt;::is_specialized
</code></entry>
<entry>true or false</entry>
</row>
<row>
<entry><code>std::numeric_limits&lt;T&gt;::is_integer</code></entry>
<entry>true or false</entry>
</row>
<row>
<entry><code>std::numeric_limits&lt;T&gt;::is_signed</code></entry>
<entry>true or false</entry>
</row>
<row>
<entry><code>os &lt;&lt; t</code></entry>
<entry>os &amp;</entry>
</row>
<row>
<entry><code>is &gt;&gt; t</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>
</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; 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 = 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>
</tbody>
</tgroup>
</table>
</section>
<section>
<title>Models</title>
<para><code>int, float, safe_signed_integer&lt;int&gt;,
safe_signed_range&lt;int&gt;, etc.</code></para>
</section>
<section>
<title>Header</title>
<para><ulink url="../../include/concept/numeric.hpp"><code>#include
&lt;boost/numeric/safe_numerics/concepts/numeric.hpp&gt;
</code></ulink></para>
</section>
</section>