Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / math / doc / html / math_toolkit / powers / expm1.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>expm1</title>
5 <link rel="stylesheet" href="../../math.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../../index.html" title="Math Toolkit 2.11.0">
8 <link rel="up" href="../powers.html" title="Basic Functions">
9 <link rel="prev" href="log1p.html" title="log1p">
10 <link rel="next" href="cbrt.html" title="cbrt">
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="log1p.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../powers.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="cbrt.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="math_toolkit.powers.expm1"></a><a class="link" href="expm1.html" title="expm1">expm1</a>
28 </h3></div></div></div>
29 <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">math</span><span class="special">/</span><span class="identifier">special_functions</span><span class="special">/</span><span class="identifier">expm1</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
30 </pre>
31 <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">math</span><span class="special">{</span>
32
33 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
34 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">expm1</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">x</span><span class="special">);</span>
35
36 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../policy.html" title="Chapter&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
37 <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>calculated-result-type</em></span></a> <span class="identifier">expm1</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../../policy.html" title="Chapter&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&amp;);</span>
38
39 <span class="special">}}</span> <span class="comment">// namespaces</span>
40 </pre>
41 <p>
42         Returns e<sup>x</sup> - 1.
43       </p>
44 <p>
45         The return type of this function is computed using the <a class="link" href="../result_type.html" title="Calculation of the Type of the Result"><span class="emphasis"><em>result
46         type calculation rules</em></span></a>: the return is <code class="computeroutput"><span class="keyword">double</span></code>
47         when <span class="emphasis"><em>x</em></span> is an integer type and T otherwise.
48       </p>
49 <p>
50         The final <a class="link" href="../../policy.html" title="Chapter&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can
51         be used to control the behaviour of the function: how it handles errors,
52         what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter&#160;20.&#160;Policies: Controlling Precision, Error Handling etc">policy
53         documentation for more details</a>.
54       </p>
55 <p>
56         For small <span class="emphasis"><em>x</em></span>, then <code class="computeroutput">e<sup>x</sup></code> is very close to 1, as a result calculating
57         <code class="computeroutput">e<sup>x</sup> - 1</code> results in catastrophic cancellation errors when <span class="emphasis"><em>x</em></span> is
58         small. <code class="computeroutput"><span class="identifier">expm1</span></code> calculates <code class="computeroutput">e<sup>x</sup> - 1</code> using
59         rational approximations (for up to 128-bit long doubles), otherwise via a
60         series expansion when x is small (giving an accuracy of less than 2&#603;).
61       </p>
62 <p>
63         Finally when BOOST_HAS_EXPM1 is defined then the <code class="computeroutput"><span class="keyword">float</span><span class="special">/</span><span class="keyword">double</span><span class="special">/</span><span class="keyword">long</span> <span class="keyword">double</span></code>
64         specializations of this template simply forward to the platform's native
65         (POSIX) implementation of this function.
66       </p>
67 <p>
68         The following graph illustrates the behaviour of expm1:
69       </p>
70 <div class="blockquote"><blockquote class="blockquote"><p>
71           <span class="inlinemediaobject"><img src="../../../graphs/expm1.svg" align="middle"></span>
72
73         </p></blockquote></div>
74 <h5>
75 <a name="math_toolkit.powers.expm1.h0"></a>
76         <span class="phrase"><a name="math_toolkit.powers.expm1.accuracy"></a></span><a class="link" href="expm1.html#math_toolkit.powers.expm1.accuracy">Accuracy</a>
77       </h5>
78 <p>
79         For built in floating point types <code class="computeroutput"><span class="identifier">expm1</span></code>
80         should have approximately 1 epsilon accuracy.
81       </p>
82 <div class="table">
83 <a name="math_toolkit.powers.expm1.table_expm1"></a><p class="title"><b>Table&#160;8.82.&#160;Error rates for expm1</b></p>
84 <div class="table-contents"><table class="table" summary="Error rates for expm1">
85 <colgroup>
86 <col>
87 <col>
88 <col>
89 <col>
90 <col>
91 </colgroup>
92 <thead><tr>
93 <th>
94               </th>
95 <th>
96                 <p>
97                   GNU C++ version 7.1.0<br> linux<br> long double
98                 </p>
99               </th>
100 <th>
101                 <p>
102                   GNU C++ version 7.1.0<br> linux<br> double
103                 </p>
104               </th>
105 <th>
106                 <p>
107                   Sun compiler version 0x5150<br> Sun Solaris<br> long double
108                 </p>
109               </th>
110 <th>
111                 <p>
112                   Microsoft Visual C++ version 14.1<br> Win32<br> double
113                 </p>
114               </th>
115 </tr></thead>
116 <tbody><tr>
117 <td>
118                 <p>
119                   Random test data
120                 </p>
121               </td>
122 <td>
123                 <p>
124                   <span class="blue">Max = 0.992&#949; (Mean = 0.402&#949;)</span><br> <br>
125                   (<span class="emphasis"><em>&lt;cmath&gt;:</em></span> Max = 0.992&#949; (Mean = 0.402&#949;))<br>
126                   (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0.992&#949; (Mean = 0.402&#949;))
127                 </p>
128               </td>
129 <td>
130                 <p>
131                   <span class="blue">Max = 0.793&#949; (Mean = 0.126&#949;)</span><br> <br>
132                   (<span class="emphasis"><em>Rmath 3.2.3:</em></span> Max = 0.793&#949; (Mean = 0.126&#949;))
133                 </p>
134               </td>
135 <td>
136                 <p>
137                   <span class="blue">Max = 1.31&#949; (Mean = 0.428&#949;)</span><br> <br>
138                   (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 0.996&#949; (Mean = 0.426&#949;))
139                 </p>
140               </td>
141 <td>
142                 <p>
143                   <span class="blue">Max = 1.31&#949; (Mean = 0.496&#949;)</span><br> <br>
144                   (<span class="emphasis"><em>&lt;math.h&gt;:</em></span> Max = 1.31&#949; (Mean = 0.496&#949;))
145                 </p>
146               </td>
147 </tr></tbody>
148 </table></div>
149 </div>
150 <br class="table-break"><h5>
151 <a name="math_toolkit.powers.expm1.h1"></a>
152         <span class="phrase"><a name="math_toolkit.powers.expm1.testing"></a></span><a class="link" href="expm1.html#math_toolkit.powers.expm1.testing">Testing</a>
153       </h5>
154 <p>
155         A mixture of spot test sanity checks, and random high precision test values
156         calculated using NTL::RR at 1000-bit precision.
157       </p>
158 </div>
159 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
160 <td align="left"></td>
161 <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2019 Nikhar
162       Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
163       Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
164       R&#229;de, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
165       Daryle Walker and Xiaogang Zhang<p>
166         Distributed under the Boost Software License, Version 1.0. (See accompanying
167         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>)
168       </p>
169 </div></td>
170 </tr></table>
171 <hr>
172 <div class="spirit-nav">
173 <a accesskey="p" href="log1p.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../powers.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="cbrt.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
174 </div>
175 </body>
176 </html>