289 lines
38 KiB
HTML
289 lines
38 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>mpfi_float</title>
|
|
<link rel="stylesheet" href="../../../multiprecision.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
|
|
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
|
<link rel="up" href="../interval.html" title="Interval Number Types">
|
|
<link rel="prev" href="../interval.html" title="Interval Number Types">
|
|
<link rel="next" href="../complex.html" title="Complex Number Types">
|
|
</head>
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
<table cellpadding="2" width="100%"><tr>
|
|
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
|
|
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
|
|
<td align="center"><a href="../../../../../../../libs/libraries.htm">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="../interval.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../interval.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../complex.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h4 class="title">
|
|
<a name="boost_multiprecision.tut.interval.mpfi"></a><a class="link" href="mpfi.html" title="mpfi_float">mpfi_float</a>
|
|
</h4></div></div></div>
|
|
<p>
|
|
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">mpfi</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">></span>
|
|
<span class="keyword">class</span> <span class="identifier">mpfi_float_backend</span><span class="special">;</span>
|
|
|
|
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="number">50</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfi_float_50</span><span class="special">;</span>
|
|
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="number">100</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfifloat_100</span><span class="special">;</span>
|
|
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="number">500</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfifloat_500</span><span class="special">;</span>
|
|
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="number">1000</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfi_float_1000</span><span class="special">;</span>
|
|
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="number">0</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfi_float</span><span class="special">;</span>
|
|
|
|
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
|
</pre>
|
|
<p>
|
|
The <code class="computeroutput"><span class="identifier">mpfi_float_backend</span></code>
|
|
type is used in conjunction with <code class="computeroutput"><span class="identifier">number</span></code>:
|
|
It acts as a thin wrapper around the <a href="http://perso.ens-lyon.fr/nathalie.revol/software.html" target="_top">MPFI</a>
|
|
<code class="computeroutput"><span class="identifier">mpfi_t</span></code> to provide an real-number
|
|
type that is a drop-in replacement for the native C++ floating-point types,
|
|
but with much greater precision and implementing interval arithmetic.
|
|
</p>
|
|
<p>
|
|
Type <code class="computeroutput"><span class="identifier">mpfi_float_backend</span></code>
|
|
can be used at fixed precision by specifying a non-zero <code class="computeroutput"><span class="identifier">Digits10</span></code>
|
|
template parameter, or at variable precision by setting the template argument
|
|
to zero. The <code class="computeroutput"><span class="keyword">typedef</span></code>s <code class="computeroutput"><span class="identifier">mpfi_float_50</span></code>, <code class="computeroutput"><span class="identifier">mpfi_float_100</span></code>,
|
|
<code class="computeroutput"><span class="identifier">mpfi_float_500</span></code>, <code class="computeroutput"><span class="identifier">mpfi_float_1000</span></code> provide arithmetic types
|
|
at 50, 100, 500 and 1000 decimal digits precision respectively. The <code class="computeroutput"><span class="keyword">typedef</span> <span class="identifier">mpfi_float</span></code>
|
|
provides a variable precision type whose precision can be controlled via
|
|
the <code class="computeroutput"><span class="identifier">number</span></code>s member functions.
|
|
</p>
|
|
<div class="note"><table border="0" summary="Note">
|
|
<tr>
|
|
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
|
|
<th align="left">Note</th>
|
|
</tr>
|
|
<tr><td align="left" valign="top"><p>
|
|
This type only provides <code class="computeroutput"><span class="identifier">numeric_limits</span></code>
|
|
support when the precision is fixed at compile time.
|
|
</p></td></tr>
|
|
</table></div>
|
|
<p>
|
|
As well as the usual conversions from arithmetic and string types, instances
|
|
of <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span> <span class="special">></span></code> are copy constructible and assignable
|
|
from:
|
|
</p>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
The <a href="http://perso.ens-lyon.fr/nathalie.revol/software.html" target="_top">MPFI</a>
|
|
native type <code class="computeroutput"><span class="identifier">mpfi_t</span></code>.
|
|
</li>
|
|
<li class="listitem">
|
|
The <code class="computeroutput"><span class="identifier">number</span></code> wrappers
|
|
around <a href="http://perso.ens-lyon.fr/nathalie.revol/software.html" target="_top">MPFI</a>
|
|
or <a href="http://www.mpfr.org" target="_top">MPFR</a>: <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">M</span><span class="special">></span> <span class="special">></span></code>
|
|
and <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float</span><span class="special"><</span><span class="identifier">M</span><span class="special">></span> <span class="special">></span></code>.
|
|
</li>
|
|
<li class="listitem">
|
|
There is a two argument constructor taking two <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float</span><span class="special"><</span><span class="identifier">M</span><span class="special">></span> <span class="special">></span></code>
|
|
arguments specifying the interval.
|
|
</li>
|
|
</ul></div>
|
|
<p>
|
|
It's also possible to access the underlying <code class="computeroutput"><span class="identifier">mpfi_t</span></code>
|
|
via the data() member function of <code class="computeroutput"><span class="identifier">mpfi_float_backend</span></code>.
|
|
</p>
|
|
<p>
|
|
Things you should know when using this type:
|
|
</p>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
A default constructed <code class="computeroutput"><span class="identifier">mpfi_float_backend</span></code>
|
|
is set to zero (<span class="emphasis"><em>Note that this is <span class="bold"><strong>not</strong></span>
|
|
the default <a href="http://perso.ens-lyon.fr/nathalie.revol/software.html" target="_top">MPFI</a>
|
|
behavior</em></span>).
|
|
</li>
|
|
<li class="listitem">
|
|
No changes are made to <a href="http://gmplib.org" target="_top">GMP</a> or
|
|
<a href="http://www.mpfr.org" target="_top">MPFR</a> global settings, so this
|
|
type can coexist with existing <a href="http://www.mpfr.org" target="_top">MPFR</a>
|
|
or <a href="http://gmplib.org" target="_top">GMP</a> code.
|
|
</li>
|
|
<li class="listitem">
|
|
The code can equally use <a href="http://mpir.org/" target="_top">MPIR</a>
|
|
in place of <a href="http://gmplib.org" target="_top">GMP</a> - indeed that
|
|
is the preferred option on Win32.
|
|
</li>
|
|
<li class="listitem">
|
|
This backend supports rvalue-references and is move-aware, making instantiations
|
|
of <code class="computeroutput"><span class="identifier">number</span></code> on this backend
|
|
move aware.
|
|
</li>
|
|
<li class="listitem">
|
|
Conversion from a string results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
|
being thrown if the string can not be interpreted as a valid floating-point
|
|
number.
|
|
</li>
|
|
<li class="listitem">
|
|
Division by zero results in an infinity.
|
|
</li>
|
|
</ul></div>
|
|
<p>
|
|
There are some additional non member functions for working on intervals:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span> <span class="identifier">lower</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">val</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns the lower end of the interval.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span> <span class="identifier">upper</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">val</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns the upper end of the interval.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span> <span class="identifier">median</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">val</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns the mid point of the interval.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span> <span class="identifier">width</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">val</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns the absolute width of the interval.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span> <span class="identifier">intersect</span><span class="special">(</span>
|
|
<span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span>
|
|
<span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns the interval which is the intersection of the <span class="emphasis"><em>a</em></span>
|
|
and <span class="emphasis"><em>b</em></span>. Returns an unspecified empty interval if there
|
|
is no such intersection.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span> <span class="identifier">hull</span><span class="special">(</span>
|
|
<span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span>
|
|
<span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns the interval which is the union of <span class="emphasis"><em>a</em></span> and
|
|
<span class="emphasis"><em>b</em></span>.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="keyword">bool</span> <span class="identifier">overlap</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span>
|
|
<span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns <code class="computeroutput"><span class="keyword">true</span></code> only if the intervals
|
|
<span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span> overlap.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates1</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates2</span><span class="special">></span>
|
|
<span class="keyword">bool</span> <span class="identifier">in</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates1</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span>
|
|
<span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates2</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns <code class="computeroutput"><span class="keyword">true</span></code> only if point
|
|
<span class="emphasis"><em>a</em></span> is contained within the interval <span class="emphasis"><em>b</em></span>.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="keyword">bool</span> <span class="identifier">zero_in</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns <code class="computeroutput"><span class="keyword">true</span></code> only if the interval
|
|
<span class="emphasis"><em>a</em></span> contains the value zero.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="keyword">bool</span> <span class="identifier">subset</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span>
|
|
<span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns <code class="computeroutput"><span class="keyword">true</span></code> only if <span class="emphasis"><em>a</em></span>
|
|
is a subset of <span class="emphasis"><em>b</em></span>.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="keyword">bool</span> <span class="identifier">proper_subset</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span>
|
|
<span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns <code class="computeroutput"><span class="keyword">true</span></code> only if <span class="emphasis"><em>a</em></span>
|
|
is a proper subset of <span class="emphasis"><em>b</em></span>.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="keyword">bool</span> <span class="identifier">empty</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns <code class="computeroutput"><span class="keyword">true</span></code> only if <span class="emphasis"><em>a</em></span>
|
|
is an empty interval, equivalent to <code class="computeroutput"><span class="identifier">upper</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span>
|
|
<span class="special"><</span> <span class="identifier">lower</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span></code>.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">></span>
|
|
<span class="keyword">bool</span> <span class="identifier">singleton</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfi_float_backend</span><span class="special"><</span><span class="identifier">Digits10</span><span class="special">>,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Returns <code class="computeroutput"><span class="keyword">true</span></code> if <code class="computeroutput"><span class="identifier">lower</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span> <span class="special">==</span>
|
|
<span class="identifier">upper</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span></code>.
|
|
</p>
|
|
<h6>
|
|
<a name="boost_multiprecision.tut.interval.mpfi.h0"></a>
|
|
<span class="phrase"><a name="boost_multiprecision.tut.interval.mpfi.mpfi_example"></a></span><a class="link" href="mpfi.html#boost_multiprecision.tut.interval.mpfi.mpfi_example"> MPFI
|
|
example:</a>
|
|
</h6>
|
|
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">mpfi</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
|
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">special_functions</span><span class="special">/</span><span class="identifier">gamma</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
|
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
|
|
|
|
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
|
|
|
<span class="comment">// Operations at variable precision and no numeric_limits support:</span>
|
|
<span class="identifier">mpfi_float</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
|
|
<span class="identifier">mpfi_float</span><span class="special">::</span><span class="identifier">default_precision</span><span class="special">(</span><span class="number">1000</span><span class="special">);</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">mpfi_float</span><span class="special">::</span><span class="identifier">default_precision</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// print root-2</span>
|
|
|
|
<span class="comment">// Operations at fixed precision and full numeric_limits support:</span>
|
|
<span class="identifier">mpfi_float_100</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">mpfi_float_100</span><span class="special">>::</span><span class="identifier">digits</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
|
<span class="comment">// We can use any C++ std lib function:</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">log</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// print log(2)</span>
|
|
|
|
<span class="comment">// Access the underlying data:</span>
|
|
<span class="identifier">mpfi_t</span> <span class="identifier">r</span><span class="special">;</span>
|
|
<span class="identifier">mpfi_init</span><span class="special">(</span><span class="identifier">r</span><span class="special">);</span>
|
|
<span class="identifier">mpfi_set</span><span class="special">(</span><span class="identifier">r</span><span class="special">,</span> <span class="identifier">b</span><span class="special">.</span><span class="identifier">backend</span><span class="special">().</span><span class="identifier">data</span><span class="special">());</span>
|
|
|
|
<span class="comment">// Construct some explicit intervals and perform set operations:</span>
|
|
<span class="identifier">mpfi_float_50</span> <span class="identifier">i1</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">),</span> <span class="identifier">i2</span><span class="special">(</span><span class="number">1.5</span><span class="special">,</span> <span class="number">2.5</span><span class="special">);</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">intersect</span><span class="special">(</span><span class="identifier">i1</span><span class="special">,</span> <span class="identifier">i2</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">hull</span><span class="special">(</span><span class="identifier">i1</span><span class="special">,</span> <span class="identifier">i2</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">overlap</span><span class="special">(</span><span class="identifier">i1</span><span class="special">,</span> <span class="identifier">i2</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">subset</span><span class="special">(</span><span class="identifier">i1</span><span class="special">,</span> <span class="identifier">i2</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
|
<span class="identifier">mpfi_clear</span><span class="special">(</span><span class="identifier">r</span><span class="special">);</span>
|
|
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
</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 © 2002-2019 John Maddock
|
|
and Christopher Kormanyos<p>
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
|
</p>
|
|
</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="../interval.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../interval.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../complex.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|