• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Writing a New Backend</title>
5<link rel="stylesheet" href="../../multiprecision.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
8<link rel="up" href="../tut.html" title="Tutorial">
9<link rel="prev" href="eigen.html" title="Eigen Interoperability">
10<link rel="next" href="../ref.html" title="Reference">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<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>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h3 class="title">
27<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>
28</h3></div></div></div>
29<p>
30        The formal requirements for a backend to class <code class="computeroutput"><span class="identifier">number</span></code>
31        are given in the reference, but to help speed and simplify the process there
32        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>
33        where all the methods needed to be written are declared but nothing is implemented.
34        The process of writing a new backend then simplifies to:
35      </p>
36<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
37<li class="listitem">
38            Save skeleton_backend.hpp under a new name and change its #include guards
39            to match.
40          </li>
41<li class="listitem">
42            Search and replace <code class="computeroutput"><span class="identifier">skeleton_backend</span></code>
43            to the name of the new backend type.
44          </li>
45<li class="listitem">
46            Fill in the blanks in the class definition and for the compulsary non-members.
47          </li>
48<li class="listitem">
49            Don't forget to mark the functions as <code class="computeroutput"><span class="keyword">inline</span></code>,
50            <code class="computeroutput"><span class="keyword">constexpr</span></code> and <code class="computeroutput"><span class="keyword">noexcept</span></code> as required.
51          </li>
52<li class="listitem">
53            Optionally fill in some of the optional methods - the header declares
54            these in rather verbose form, for example with overloads for every single
55            arithmetic type. No sane backend would ever implement all of these, just
56            choose the ones that make sense and leave the others.
57          </li>
58<li class="listitem">
59            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.
60          </li>
61</ul></div>
62<p>
63        To test the new backend, start with a basic arithmetic test, this is a test
64        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>
65        that looks something like:
66      </p>
67<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</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">&gt;</span>
68<span class="preprocessor">#include</span> <span class="string">"test_arithmetic.hpp"</span>
69
70<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
71<span class="special">{</span>
72   <span class="identifier">test</span><span class="special">&lt;</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">&gt;();</span>
73   <span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">report_errors</span><span class="special">();</span>
74<span class="special">}</span>
75</pre>
76<p>
77        This will basically "instantiate everything", and perform a few
78        runtime sanity checks; it is a very good test that you have written legal
79        code!
80      </p>
81<p>
82        You should also create a "header include test" that verifies that
83        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>
84        for an example.
85      </p>
86<p>
87        For integer types, you should add the new type to at least the following
88        tests as well:
89      </p>
90<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
91<li class="listitem">
92            test_hash.cpp
93          </li>
94<li class="listitem">
95            test_int_io.cpp
96          </li>
97<li class="listitem">
98            test_move.cpp
99          </li>
100<li class="listitem">
101            test_numeric_limits.cpp
102          </li>
103</ul></div>
104<p>
105        For floating point types, you should add the new type to at least the following
106        tests as well:
107      </p>
108<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
109<li class="listitem">
110            test_acos.cpp
111          </li>
112<li class="listitem">
113            test_asin.cpp
114          </li>
115<li class="listitem">
116            test_atan.cpp
117          </li>
118<li class="listitem">
119            test_constants.cpp
120          </li>
121<li class="listitem">
122            test_cos.cpp
123          </li>
124<li class="listitem">
125            test_cosh.cpp
126          </li>
127<li class="listitem">
128            test_exp.cpp
129          </li>
130<li class="listitem">
131            test_float_io.cpp
132          </li>
133<li class="listitem">
134            test_fpclassify.cpp
135          </li>
136<li class="listitem">
137            test_hash.cpp
138          </li>
139<li class="listitem">
140            test_log.cpp
141          </li>
142<li class="listitem">
143            test_move.cpp
144          </li>
145<li class="listitem">
146            test_numeric_limits.cpp
147          </li>
148<li class="listitem">
149            test_pow.cpp
150          </li>
151<li class="listitem">
152            test_round.cpp
153          </li>
154<li class="listitem">
155            test_sf_import_c99.cpp
156          </li>
157<li class="listitem">
158            test_sin.cpp
159          </li>
160<li class="listitem">
161            test_sinh.cpp
162          </li>
163<li class="listitem">
164            test_sqrt.cpp
165          </li>
166<li class="listitem">
167            test_tan.cpp
168          </li>
169<li class="listitem">
170            test_tanh.cpp
171          </li>
172<li class="listitem">
173            concepts/number_concept_check.cpp
174          </li>
175<li class="listitem">
176            concepts/sf_concept_check_basic.cpp
177          </li>
178<li class="listitem">
179            concepts/sf_concept_check_bessel.cpp
180          </li>
181<li class="listitem">
182            concepts/sf_concept_check_beta.cpp
183          </li>
184<li class="listitem">
185            concepts/sf_concept_check_beta_2.cpp
186          </li>
187<li class="listitem">
188            concepts/sf_concept_check_beta_3.cpp
189          </li>
190<li class="listitem">
191            concepts/sf_concept_check_elliptic.cpp
192          </li>
193<li class="listitem">
194            concepts/sf_concept_check_gamma.cpp
195          </li>
196<li class="listitem">
197            concepts/sf_concept_check_poly.cpp
198          </li>
199</ul></div>
200</div>
201<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
202<td align="left"></td>
203<td align="right"><div class="copyright-footer">Copyright © 2002-2020 John
204      Maddock and Christopher Kormanyos<p>
205        Distributed under the Boost Software License, Version 1.0. (See accompanying
206        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>)
207      </p>
208</div></td>
209</tr></table>
210<hr>
211<div class="spirit-nav">
212<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>
213</div>
214</body>
215</html>
216