mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-12 23:26:15 -05:00
233 lines
35 KiB
HTML
233 lines
35 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>Polynomial and Rational Function Evaluation</title>
|
|
<link rel="stylesheet" href="../../math.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
|
<link rel="home" href="../../index.html" title="Math Toolkit 2.4.0">
|
|
<link rel="up" href="../internals.html" title="Internal tools">
|
|
<link rel="prev" href="cf.html" title="Continued Fraction Evaluation">
|
|
<link rel="next" href="tuples.html" title="Tuples">
|
|
</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="cf.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../internals.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="tuples.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="math_toolkit.roots.rational"></a><a class="link" href="rational.html" title="Polynomial and Rational Function Evaluation">Polynomial and Rational
|
|
Function Evaluation</a>
|
|
</h3></div></div></div>
|
|
<h5>
|
|
<a name="math_toolkit.roots.rational.h0"></a>
|
|
<span class="phrase"><a name="math_toolkit.roots.rational.synopsis"></a></span><a class="link" href="rational.html#math_toolkit.roots.rational.synopsis">synopsis</a>
|
|
</h5>
|
|
<pre class="programlisting"><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">tools</span><span class="special">/</span><span class="identifier">rational</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
|
</pre>
|
|
<pre class="programlisting"><span class="comment">// Polynomials:</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">(&</span><span class="identifier">poly</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">val</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">N</span><span class="special">>&</span> <span class="identifier">poly</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">val</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">U</span> <span class="identifier">evaluate_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">poly</span><span class="special">,</span> <span class="identifier">U</span> <span class="identifier">z</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">count</span><span class="special">);</span>
|
|
|
|
<span class="comment">// Even polynomials:</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_even_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">(&</span><span class="identifier">poly</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_even_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">N</span><span class="special">>&</span> <span class="identifier">poly</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">U</span> <span class="identifier">evaluate_even_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">poly</span><span class="special">,</span> <span class="identifier">U</span> <span class="identifier">z</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">count</span><span class="special">);</span>
|
|
|
|
<span class="comment">// Odd polynomials </span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_odd_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">(&</span><span class="identifier">a</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_odd_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">N</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">U</span> <span class="identifier">evaluate_odd_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">poly</span><span class="special">,</span> <span class="identifier">U</span> <span class="identifier">z</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">count</span><span class="special">);</span>
|
|
|
|
<span class="comment">// Rational Functions:</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_rational</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">(&</span><span class="identifier">a</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">(&</span><span class="identifier">b</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_rational</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">N</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">N</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_rational</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">num</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">U</span><span class="special">*</span> <span class="identifier">denom</span><span class="special">,</span> <span class="identifier">V</span> <span class="identifier">z</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">count</span><span class="special">);</span>
|
|
</pre>
|
|
<h5>
|
|
<a name="math_toolkit.roots.rational.h1"></a>
|
|
<span class="phrase"><a name="math_toolkit.roots.rational.description"></a></span><a class="link" href="rational.html#math_toolkit.roots.rational.description">Description</a>
|
|
</h5>
|
|
<p>
|
|
Each of the functions come in three variants: a pair of overloaded functions
|
|
where the order of the polynomial or rational function is evaluated at compile
|
|
time, and an overload that accepts a runtime variable for the size of the
|
|
coefficient array. Generally speaking, compile time evaluation of the array
|
|
size results in better type safety, is less prone to programmer errors, and
|
|
may result in better optimised code. The polynomial evaluation functions
|
|
in particular, are specialised for various array sizes, allowing for loop
|
|
unrolling, and one hopes, optimal inline expansion.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">(&</span><span class="identifier">poly</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">val</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">N</span><span class="special">>&</span> <span class="identifier">poly</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">val</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">U</span> <span class="identifier">evaluate_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">poly</span><span class="special">,</span> <span class="identifier">U</span> <span class="identifier">z</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">count</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Evaluates the <a href="http://en.wikipedia.org/wiki/Polynomial" target="_top">polynomial</a>
|
|
described by the coefficients stored in <span class="emphasis"><em>poly</em></span>.
|
|
</p>
|
|
<p>
|
|
If the size of the array is specified at runtime, then the polynomial most
|
|
have order <span class="emphasis"><em>count-1</em></span> with <span class="emphasis"><em>count</em></span> coefficients.
|
|
Otherwise it has order <span class="emphasis"><em>N-1</em></span> with <span class="emphasis"><em>N</em></span>
|
|
coefficients.
|
|
</p>
|
|
<p>
|
|
Coefficients should be stored such that the coefficients for the x<sup>i </sup> terms
|
|
are in poly[i].
|
|
</p>
|
|
<p>
|
|
The types of the coefficients and of variable <span class="emphasis"><em>z</em></span> may
|
|
differ as long as <span class="emphasis"><em>*poly</em></span> is convertible to type <span class="emphasis"><em>U</em></span>.
|
|
This allows, for example, for the coefficient table to be a table of integers
|
|
if this is appropriate.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_even_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">(&</span><span class="identifier">poly</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_even_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">N</span><span class="special">>&</span> <span class="identifier">poly</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">U</span> <span class="identifier">evaluate_even_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">poly</span><span class="special">,</span> <span class="identifier">U</span> <span class="identifier">z</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">count</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
As above, but evaluates an even polynomial: one where all the powers of
|
|
<span class="emphasis"><em>z</em></span> are even numbers. Equivalent to calling <code class="computeroutput"><span class="identifier">evaluate_polynomial</span><span class="special">(</span><span class="identifier">poly</span><span class="special">,</span> <span class="identifier">z</span><span class="special">*</span><span class="identifier">z</span><span class="special">,</span> <span class="identifier">count</span><span class="special">)</span></code>.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_odd_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">(&</span><span class="identifier">a</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_odd_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">N</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">U</span> <span class="identifier">evaluate_odd_polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">poly</span><span class="special">,</span> <span class="identifier">U</span> <span class="identifier">z</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">count</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
As above but evaluates a polynomial where all the powers are odd numbers.
|
|
Equivalent to <code class="computeroutput"><span class="identifier">evaluate_polynomial</span><span class="special">(</span><span class="identifier">poly</span><span class="special">+</span><span class="number">1</span><span class="special">,</span> <span class="identifier">z</span><span class="special">*</span><span class="identifier">z</span><span class="special">,</span>
|
|
<span class="identifier">count</span><span class="special">-</span><span class="number">1</span><span class="special">)</span> <span class="special">*</span>
|
|
<span class="identifier">z</span> <span class="special">+</span> <span class="identifier">poly</span><span class="special">[</span><span class="number">0</span><span class="special">]</span></code>.
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_rational</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">(&</span><span class="identifier">num</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> <span class="keyword">const</span> <span class="identifier">U</span><span class="special">(&</span><span class="identifier">denom</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_rational</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">N</span><span class="special">>&</span> <span class="identifier">num</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="identifier">U</span><span class="special">,</span><span class="identifier">N</span><span class="special">>&</span> <span class="identifier">denom</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">V</span><span class="special">&</span> <span class="identifier">z</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">V</span><span class="special">></span>
|
|
<span class="identifier">V</span> <span class="identifier">evaluate_rational</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">num</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">U</span><span class="special">*</span> <span class="identifier">denom</span><span class="special">,</span> <span class="identifier">V</span> <span class="identifier">z</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">count</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
Evaluates the rational function (the ratio of two polynomials) described
|
|
by the coefficients stored in <span class="emphasis"><em>num</em></span> and <span class="emphasis"><em>demom</em></span>.
|
|
</p>
|
|
<p>
|
|
If the size of the array is specified at runtime then both polynomials most
|
|
have order <span class="emphasis"><em>count-1</em></span> with <span class="emphasis"><em>count</em></span> coefficients.
|
|
Otherwise both polynomials have order <span class="emphasis"><em>N-1</em></span> with <span class="emphasis"><em>N</em></span>
|
|
coefficients.
|
|
</p>
|
|
<p>
|
|
Array <span class="emphasis"><em>num</em></span> describes the numerator, and <span class="emphasis"><em>demon</em></span>
|
|
the denominator.
|
|
</p>
|
|
<p>
|
|
Coefficients should be stored such that the coefficients for the x<sup>i </sup> terms
|
|
are in num[i] and denom[i].
|
|
</p>
|
|
<p>
|
|
The types of the coefficients and of variable <span class="emphasis"><em>v</em></span> may
|
|
differ as long as <span class="emphasis"><em>*num</em></span> and <span class="emphasis"><em>*denom</em></span>
|
|
are convertible to type <span class="emphasis"><em>V</em></span>. This allows, for example,
|
|
for one or both of the coefficient tables to be a table of integers if this
|
|
is appropriate.
|
|
</p>
|
|
<p>
|
|
These functions are designed to safely evaluate the result, even when the
|
|
value <span class="emphasis"><em>z</em></span> is very large. As such they do not take advantage
|
|
of compile time array sizes to make any optimisations. These functions are
|
|
best reserved for situations where <span class="emphasis"><em>z</em></span> may be large: if
|
|
you can be sure that numerical overflow will not occur then polynomial evaluation
|
|
with compile-time array sizes may offer slightly better performance.
|
|
</p>
|
|
<h5>
|
|
<a name="math_toolkit.roots.rational.h2"></a>
|
|
<span class="phrase"><a name="math_toolkit.roots.rational.implementation"></a></span><a class="link" href="rational.html#math_toolkit.roots.rational.implementation">Implementation</a>
|
|
</h5>
|
|
<p>
|
|
Polynomials are evaluated by <a href="http://en.wikipedia.org/wiki/Horner_algorithm" target="_top">Horners
|
|
method</a>. If the array size is known at compile time then the functions
|
|
dispatch to size-specific implementations that unroll the evaluation loop.
|
|
</p>
|
|
<p>
|
|
Rational evaluation is by <a href="http://en.wikipedia.org/wiki/Horner_algorithm" target="_top">Horners
|
|
method</a>: with the two polynomials being evaluated in parallel to make
|
|
the most of the processors floating-point pipeline. If <span class="emphasis"><em>v</em></span>
|
|
is greater than one, then the polynomials are evaluated in reverse order
|
|
as polynomials in <span class="emphasis"><em>1/v</em></span>: this avoids unnecessary numerical
|
|
overflow when the coefficients are large.
|
|
</p>
|
|
<p>
|
|
Both the polynomial and rational function evaluation algorithms can be tuned
|
|
using various configuration macros to provide optimal performance for a particular
|
|
combination of compiler and platform. This includes support for second-order
|
|
Horner's methods. The various options are <a class="link" href="../tuning.html" title="Performance Tuning Macros">documented
|
|
here</a>. However, the performance benefits to be gained from these are
|
|
marginal on most current hardware, consequently it's best to run the <a class="link" href="../perf_test_app.html" title="The Performance Test Applications">performance test application</a>
|
|
before changing the default settings.
|
|
</p>
|
|
</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 © 2006-2010, 2012-2014 Nikhar Agrawal,
|
|
Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
|
|
Holin, Bruno Lalande, John Maddock, Johan Råde, Gautam Sewani, Benjamin Sobotta,
|
|
Thijs van den Berg, Daryle Walker and Xiaogang Zhang<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="cf.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../internals.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="tuples.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|