mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-10 23:52:27 +00:00
270 lines
11 KiB
HTML
270 lines
11 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>interval<typename R></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_integer_arithmetic.html" title="Checked Integer Arithmetic">
|
|
<link rel="next" href="performance_tests.html" title="Performance Tests">
|
|
</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_integer_arithmetic.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="performance_tests.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.interval"></a>interval<typename R></h3></div></div></div>
|
|
<div class="toc"><dl>
|
|
<dt><span class="section"><a href="interval.html#idm473861313552">Description</a></span></dt>
|
|
<dt><span class="section"><a href="interval.html#idm473861312320">Template Parameters</a></span></dt>
|
|
<dt><span class="section"><a href="interval.html#idm473861310448">Notation</a></span></dt>
|
|
<dt><span class="section"><a href="interval.html#idm473861294816">Associated Types</a></span></dt>
|
|
<dt><span class="section"><a href="interval.html#idm473861289008">Valid Expressions</a></span></dt>
|
|
<dt><span class="section"><a href="interval.html#idm473861227952">Header</a></span></dt>
|
|
<dt><span class="section"><a href="interval.html#idm473861226288">Example of use</a></span></dt>
|
|
</dl></div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861313552"></a>Description</h4></div></div></div>
|
|
<p>A closed arithmetic interval represented by a pair of elements of
|
|
type R.</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861312320"></a>Template Parameters</h4></div></div></div>
|
|
<p>R must model the type requirements <a class="link" href="numeric.html" title="Numeric<T>">Numeric</a></p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861310448"></a>Notation</h4></div></div></div>
|
|
<div class="informaltable"><table class="table">
|
|
<colgroup>
|
|
<col align="left">
|
|
<col align="left">
|
|
</colgroup>
|
|
<thead><tr>
|
|
<th align="left">Symbol</th>
|
|
<th align="left">Description</th>
|
|
</tr></thead>
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">I</code></td>
|
|
<td align="left">An interval type</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">i, j</code></td>
|
|
<td align="left">An interval</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">R, T</code></td>
|
|
<td align="left">Numeric types which can be used to make an interval</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">l, u</code></td>
|
|
<td align="left">lower and upper Numeric limits of an interval</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">C</code></td>
|
|
<td align="left">checked_result<interval<R>></td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">os</code></td>
|
|
<td align="left">std::basic_ostream<Char, CharT></td>
|
|
</tr>
|
|
</tbody>
|
|
</table></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861294816"></a>Associated Types</h4></div></div></div>
|
|
<div class="informaltable"><table class="table">
|
|
<colgroup>
|
|
<col align="left">
|
|
<col align="left">
|
|
</colgroup>
|
|
<tbody><tr>
|
|
<td align="left"><a class="link" href="checked_result.html" title="checked_result<typename R>"><code class="computeroutput">checked_result</code></a></td>
|
|
<td align="left">holds either the result of an operation or information as
|
|
to why it failed</td>
|
|
</tr></tbody>
|
|
</table></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861289008"></a>Valid Expressions</h4></div></div></div>
|
|
<p>Note that all expressions are constexpr .</p>
|
|
<div class="informaltable"><table class="table">
|
|
<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">interval<R>(l, u)</code></td>
|
|
<td align="left"><code class="computeroutput">interval<R></code></td>
|
|
<td align="left">construct a new interval from a pair of limits</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">interval<R>(p)</code></td>
|
|
<td align="left"><code class="computeroutput">interval<R></code></td>
|
|
<td align="left">construct a new interval from a pair of limits</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">interval<R>(i)</code></td>
|
|
<td align="left"><code class="computeroutput">interval<R></code></td>
|
|
<td align="left">copy constructor</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">i.includes(j)</code></td>
|
|
<td align="left"><code class="computeroutput">bool</code></td>
|
|
<td align="left">return true if interval i includes interval j</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">i.includes(t)</code></td>
|
|
<td align="left"><code class="computeroutput">bool</code></td>
|
|
<td align="left">return true if interval i includes value t</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">add<R>(i, j)</code></td>
|
|
<td align="left"><code class="computeroutput">C</code></td>
|
|
<td align="left">add two intervals and return the result</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">subtract<R>(i, j)</code></td>
|
|
<td align="left"><code class="computeroutput">C</code></td>
|
|
<td align="left">subtract two intervals and return the result</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">multiply<R>(i, j)</code></td>
|
|
<td align="left"><code class="computeroutput">C</code></td>
|
|
<td align="left">multiply two intervals and return the result</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">divide_nz<R>(i, j)</code></td>
|
|
<td align="left"><code class="computeroutput">C</code></td>
|
|
<td align="left">divide one interval by another excluding the value zero
|
|
and return the result</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">divide<R>(i, j)</code></td>
|
|
<td align="left"><code class="computeroutput">C</code></td>
|
|
<td align="left">divide one interval by another and return the
|
|
result</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">modulus_nz<R>(i, j)</code></td>
|
|
<td align="left"><code class="computeroutput">C</code></td>
|
|
<td align="left">calculate modulus of one interval by another excluding
|
|
the value zero and return the result</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">modulus<R>(i, j)</code></td>
|
|
<td align="left"><code class="computeroutput">C</code></td>
|
|
<td align="left">calculate modulus of one interval by another and return
|
|
the result</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">left_shift<R>(i, j)</code></td>
|
|
<td align="left"><code class="computeroutput">C</code></td>
|
|
<td align="left">calculate the range that would result from shifting one
|
|
interval by another</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">right_shift<R>(i, j)</code></td>
|
|
<td align="left"><code class="computeroutput">C</code></td>
|
|
<td align="left">calculate the range that would result from shifting one
|
|
interval by another</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t < u</code></td>
|
|
<td align="left"><code class="computeroutput">boost::logic::tribool</code></td>
|
|
<td align="left">true if every element in t is less than every element in
|
|
u</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t > u</code></td>
|
|
<td align="left"><code class="computeroutput">boost::logic::tribool</code></td>
|
|
<td align="left">true if every element in t is greater than every element
|
|
in u</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t <= u</code></td>
|
|
<td align="left"><code class="computeroutput">boost::logic::tribool</code></td>
|
|
<td align="left">true if every element in t is less than or equal to every
|
|
element in u</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t >= u</code></td>
|
|
<td align="left"><code class="computeroutput">boost::logic::tribool</code></td>
|
|
<td align="left">true if every element in t is greater than or equal to
|
|
every element in u</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t == u</code></td>
|
|
<td align="left"><code class="computeroutput">bool</code></td>
|
|
<td align="left">true if limits are equal</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">t != u</code></td>
|
|
<td align="left"><code class="computeroutput">bool</code></td>
|
|
<td align="left">true if limits are not equal</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left"><code class="computeroutput">os << i</code></td>
|
|
<td align="left"><code class="computeroutput">os &</code></td>
|
|
<td align="left">print interval to output stream</td>
|
|
</tr>
|
|
</tbody>
|
|
</table></div>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861227952"></a>Header</h4></div></div></div>
|
|
<p><code class="computeroutput">#include "interval.hpp"</code></p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="idm473861226288"></a>Example of use</h4></div></div></div>
|
|
<pre class="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;
|
|
}</pre>
|
|
</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_integer_arithmetic.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="performance_tests.html"><img src="images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|