216 lines
9.5 KiB
HTML
216 lines
9.5 KiB
HTML
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
<title>Writing a New Backend</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="../tut.html" title="Tutorial">
|
||
<link rel="prev" href="eigen.html" title="Eigen Interoperability">
|
||
<link rel="next" href="../ref.html" title="Reference">
|
||
</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="eigen.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.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="../ref.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="boost_multiprecision.tut.new_backend"></a><a class="link" href="new_backend.html" title="Writing a New Backend">Writing a New Backend</a>
|
||
</h3></div></div></div>
|
||
<p>
|
||
The formal requirements for a backend to class <code class="computeroutput"><span class="identifier">number</span></code>
|
||
are given in the reference, but to help speed and simplify the process there
|
||
is a header <a href="http://www.boost.org/doc/libs/release/libs/multiprecision/doc/html/../../test/skeleton_backend.hpp" target="_top">skeleton_backend.hpp</a>
|
||
where all the methods needed to be written are declared but nothing is implemented.
|
||
The process of writing a new backend then simplifies to:
|
||
</p>
|
||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||
<li class="listitem">
|
||
Save skeleton_backend.hpp under a new name and change its #include guards
|
||
to match.
|
||
</li>
|
||
<li class="listitem">
|
||
Search and replace <code class="computeroutput"><span class="identifier">skeleton_backend</span></code>
|
||
to the name of the new backend type.
|
||
</li>
|
||
<li class="listitem">
|
||
Fill in the blanks in the class definition and for the compulsary non-members.
|
||
</li>
|
||
<li class="listitem">
|
||
Don't forget to mark the functions as <code class="computeroutput"><span class="keyword">inline</span></code>,
|
||
<code class="computeroutput"><span class="keyword">constexpr</span></code> and <code class="computeroutput"><span class="keyword">noexcept</span></code> as required.
|
||
</li>
|
||
<li class="listitem">
|
||
Optionally fill in some of the optional methods - the header declares
|
||
these in rather verbose form, for example with overloads for every single
|
||
arithmetic type. No sane backend would ever implement all of these, just
|
||
choose the ones that make sense and leave the others.
|
||
</li>
|
||
<li class="listitem">
|
||
Add convenience typedefs for the actual instantiation(s) of class <code class="computeroutput"><span class="identifier">number</span></code> that will use the new backend.
|
||
</li>
|
||
</ul></div>
|
||
<p>
|
||
To test the new backend, start with a basic arithmetic test, this is a test
|
||
case under <code class="computeroutput"><span class="identifier">libs</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">test</span></code>
|
||
that looks something like:
|
||
</p>
|
||
<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">my_new_number_type</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||
<span class="preprocessor">#include</span> <span class="string">"test_arithmetic.hpp"</span>
|
||
|
||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||
<span class="special">{</span>
|
||
<span class="identifier">test</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">my_new_number_type</span><span class="special">>();</span>
|
||
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">report_errors</span><span class="special">();</span>
|
||
<span class="special">}</span>
|
||
</pre>
|
||
<p>
|
||
This will basically "instantiate everything", and perform a few
|
||
runtime sanity checks; it is a very good test that you have written legal
|
||
code!
|
||
</p>
|
||
<p>
|
||
You should also create a "header include test" that verifies that
|
||
the new header includes everything it should, see <a href="http://www.boost.org/doc/libs/release/libs/multiprecision/doc/html/../../test/include_test/mpfr_include_test.cpp" target="_top">mpfr_include_test.cpp</a>
|
||
for an example.
|
||
</p>
|
||
<p>
|
||
For integer types, you should add the new type to at least the following
|
||
tests as well:
|
||
</p>
|
||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||
<li class="listitem">
|
||
test_hash.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_int_io.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_move.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_numeric_limits.cpp
|
||
</li>
|
||
</ul></div>
|
||
<p>
|
||
For floating point types, you should add the new type to at least the following
|
||
tests as well:
|
||
</p>
|
||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||
<li class="listitem">
|
||
test_acos.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_asin.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_atan.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_constants.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_cos.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_cosh.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_exp.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_float_io.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_fpclassify.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_hash.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_log.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_move.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_numeric_limits.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_pow.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_round.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_sf_import_c99.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_sin.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_sinh.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_sqrt.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_tan.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
test_tanh.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
concepts/number_concept_check.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
concepts/sf_concept_check_basic.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
concepts/sf_concept_check_bessel.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
concepts/sf_concept_check_beta.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
concepts/sf_concept_check_beta_2.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
concepts/sf_concept_check_beta_3.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
concepts/sf_concept_check_elliptic.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
concepts/sf_concept_check_gamma.cpp
|
||
</li>
|
||
<li class="listitem">
|
||
concepts/sf_concept_check_poly.cpp
|
||
</li>
|
||
</ul></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 © 2002-2020 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="eigen.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.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="../ref.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||
</div>
|
||
</body>
|
||
</html>
|