mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-23 16:02:13 +00:00
a) made trap_exception work b) updated manual and examples to show how to use library to eliminate runtime penalty c) added in safe_literal d) made corrections of various types
334 lines
8.7 KiB
XML
334 lines
8.7 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.interval">
|
|
<title>interval<typename R></title>
|
|
|
|
<section>
|
|
<title>Description</title>
|
|
|
|
<para>A closed arithmetic interval represented by a pair of elements of
|
|
type R.</para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Template Parameters</title>
|
|
|
|
<para>R must model the type requirements <link
|
|
linkend="safe_numerics.numeric">Numeric</link></para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Notation</title>
|
|
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<colspec align="left" colwidth="1*"/>
|
|
|
|
<colspec align="left" colwidth="4*"/>
|
|
|
|
<thead>
|
|
<row>
|
|
<entry align="left">Symbol</entry>
|
|
|
|
<entry align="left">Description</entry>
|
|
</row>
|
|
</thead>
|
|
|
|
<tbody>
|
|
<row>
|
|
<entry><code>I</code></entry>
|
|
|
|
<entry>An interval type</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>i, j</code></entry>
|
|
|
|
<entry>An interval</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>R, T</code></entry>
|
|
|
|
<entry>Numeric types which can be used to make an interval</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>l, u</code></entry>
|
|
|
|
<entry>lower and upper Numeric limits of an interval</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>C</code></entry>
|
|
|
|
<entry>checked_result<interval<R>></entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>os</code></entry>
|
|
|
|
<entry>std::basic_ostream<Char, CharT></entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Associated Types</title>
|
|
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<colspec align="left" colwidth="1*"/>
|
|
|
|
<colspec align="left" colwidth="4*"/>
|
|
|
|
<tbody>
|
|
<row>
|
|
<entry><link
|
|
linkend="safenumerics.checked_result"><code>checked_result</code></link></entry>
|
|
|
|
<entry>holds either the result of an operation or information as
|
|
to why it failed</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Valid Expressions</title>
|
|
|
|
<para>Note that all expressions are constexpr .</para>
|
|
|
|
<para><informaltable>
|
|
<tgroup cols="3">
|
|
<colspec align="left" colwidth="1*"/>
|
|
|
|
<colspec align="left" colwidth="1*"/>
|
|
|
|
<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>interval<R>(l, u)</code></entry>
|
|
|
|
<entry><code>interval<R></code></entry>
|
|
|
|
<entry>construct a new interval from a pair of limits</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>interval<R>(p)</code></entry>
|
|
|
|
<entry><code>interval<R></code></entry>
|
|
|
|
<entry>construct a new interval from a pair of limits</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>interval<R>(i)</code></entry>
|
|
|
|
<entry><code>interval<R></code></entry>
|
|
|
|
<entry>copy constructor</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>i.includes(j)</code></entry>
|
|
|
|
<entry><code>bool</code></entry>
|
|
|
|
<entry>return true if interval i includes interval j</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>i.includes(t)</code></entry>
|
|
|
|
<entry><code>bool</code></entry>
|
|
|
|
<entry>return true if interval i includes value t</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>add<R>(i, j)</code></entry>
|
|
|
|
<entry><code>C</code></entry>
|
|
|
|
<entry>add two intervals and return the result</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>subtract<R>(i, j)</code></entry>
|
|
|
|
<entry><code>C</code></entry>
|
|
|
|
<entry>subtract two intervals and return the result</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>multiply<R>(i, j)</code></entry>
|
|
|
|
<entry><code>C</code></entry>
|
|
|
|
<entry>multiply two intervals and return the result</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>divide_nz<R>(i, j)</code></entry>
|
|
|
|
<entry><code>C</code></entry>
|
|
|
|
<entry>divide one interval by another excluding the value zero
|
|
and return the result</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>divide<R>(i, j)</code></entry>
|
|
|
|
<entry><code>C</code></entry>
|
|
|
|
<entry>divide one interval by another and return the
|
|
result</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>modulus_nz<R>(i, j)</code></entry>
|
|
|
|
<entry><code>C</code></entry>
|
|
|
|
<entry>calculate modulus of one interval by another excluding
|
|
the value zero and return the result</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>modulus<R>(i, j)</code></entry>
|
|
|
|
<entry><code>C</code></entry>
|
|
|
|
<entry>calculate modulus of one interval by another and return
|
|
the result</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>left_shift<R>(i, j)</code></entry>
|
|
|
|
<entry><code>C</code></entry>
|
|
|
|
<entry>calculate the range that would result from shifting one
|
|
interval by another</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>right_shift<R>(i, j)</code></entry>
|
|
|
|
<entry><code>C</code></entry>
|
|
|
|
<entry>calculate the range that would result from shifting one
|
|
interval by another</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>t < u</code></entry>
|
|
|
|
<entry><code>boost::logic::tribool</code></entry>
|
|
|
|
<entry>true if every element in t is less than every element in
|
|
u</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>t > u</code></entry>
|
|
|
|
<entry><code>boost::logic::tribool</code></entry>
|
|
|
|
<entry>true if every element in t is greater than every element
|
|
in u</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>t <= u</code></entry>
|
|
|
|
<entry><code>boost::logic::tribool</code></entry>
|
|
|
|
<entry>true if every element in t is less than or equal to every
|
|
element in u</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>t >= u</code></entry>
|
|
|
|
<entry><code>boost::logic::tribool</code></entry>
|
|
|
|
<entry>true if every element in t is greater than or equal to
|
|
every element in u</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>t == u</code></entry>
|
|
|
|
<entry><code>bool</code></entry>
|
|
|
|
<entry>true if limits are equal</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>t != u</code></entry>
|
|
|
|
<entry><code>bool</code></entry>
|
|
|
|
<entry>true if limits are not equal</entry>
|
|
</row>
|
|
|
|
<row>
|
|
<entry><code>os << i</code></entry>
|
|
|
|
<entry><code>os &</code></entry>
|
|
|
|
<entry>print interval to output stream</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable></para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Header</title>
|
|
|
|
<para><code>#include "interval.hpp"</code></para>
|
|
</section>
|
|
|
|
<section>
|
|
<title>Example of use</title>
|
|
|
|
<programlisting>#include <iostream>
|
|
#include <cstdint>
|
|
#include <cassert>
|
|
#include <boost/numeric/interval.hpp>
|
|
|
|
int main(){
|
|
std::cout << "test1" << std::endl;
|
|
interval<std::int16_t> x = {-64, 63};
|
|
std::cout << "x = " << x << std::endl;
|
|
interval<std::int16_t> y(-128, 126);
|
|
std::cout << "y = " << y << std::endl;
|
|
assert(static_cast<interval<std::int16_t>>(add<std::int16_t>(x,x)) == y);
|
|
std::cout << "x + x =" << add<std::int16_t>(x, x) << std::endl;
|
|
std::cout << "x - x = " << subtract<std::int16_t>(x, x) << std::endl;
|
|
return 0;
|
|
}</programlisting>
|
|
</section>
|
|
</section>
|