1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>sqrt1pm1</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.12.0"> 8<link rel="up" href="../powers.html" title="Basic Functions"> 9<link rel="prev" href="cbrt.html" title="cbrt"> 10<link rel="next" href="powm1.html" title="powm1"> 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="cbrt.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="powm1.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.sqrt1pm1"></a><a class="link" href="sqrt1pm1.html" title="sqrt1pm1">sqrt1pm1</a> 28</h3></div></div></div> 29<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">special_functions</span><span class="special">/</span><span class="identifier">sqrt1pm1</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 30</pre> 31<p> 32 namespace boost{ namespace math{ 33 </p> 34<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 35<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">sqrt1pm1</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">x</span><span class="special">);</span> 36 37<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> <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">></span> 38<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">sqrt1pm1</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 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&);</span> 39 40<span class="special">}}</span> <span class="comment">// namespaces</span> 41</pre> 42<p> 43 Returns <code class="computeroutput"><span class="identifier">sqrt</span><span class="special">(</span><span class="number">1</span><span class="special">+</span><span class="identifier">x</span><span class="special">)</span> <span class="special">-</span> <span class="number">1</span></code>. 44 </p> 45<p> 46 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 47 type calculation rules</em></span></a>: the return is <code class="computeroutput"><span class="keyword">double</span></code> 48 when <span class="emphasis"><em>x</em></span> is an integer-type and T otherwise. 49 </p> 50<p> 51 The final <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a> argument is optional and can 52 be used to control the behaviour of the function: how it handles errors, 53 what level of precision to use etc. Refer to the <a class="link" href="../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">policy 54 documentation for more details</a>. 55 </p> 56<p> 57 This function is useful when you need the difference between <code class="computeroutput"><span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code> and 1, when <span class="emphasis"><em>x</em></span> is itself 58 close to 1. 59 </p> 60<p> 61 Implemented in terms of <code class="computeroutput"><span class="identifier">log1p</span></code> 62 and <code class="computeroutput"><span class="identifier">expm1</span></code>. 63 </p> 64<p> 65 The following graph illustrates the behaviour of sqrt1pm1: 66 </p> 67<div class="blockquote"><blockquote class="blockquote"><p> 68 <span class="inlinemediaobject"><img src="../../../graphs/sqrt1pm1.svg" align="middle"></span> 69 70 </p></blockquote></div> 71<h5> 72<a name="math_toolkit.powers.sqrt1pm1.h0"></a> 73 <span class="phrase"><a name="math_toolkit.powers.sqrt1pm1.accuracy"></a></span><a class="link" href="sqrt1pm1.html#math_toolkit.powers.sqrt1pm1.accuracy">Accuracy</a> 74 </h5> 75<p> 76 For built in floating-point types <code class="computeroutput"><span class="identifier">sqrt1pm1</span></code> 77 should have approximately 3 epsilon accuracy. 78 </p> 79<div class="table"> 80<a name="math_toolkit.powers.sqrt1pm1.table_sqrt1pm1"></a><p class="title"><b>Table 8.84. Error rates for sqrt1pm1</b></p> 81<div class="table-contents"><table class="table" summary="Error rates for sqrt1pm1"> 82<colgroup> 83<col> 84<col> 85<col> 86<col> 87<col> 88</colgroup> 89<thead><tr> 90<th> 91 </th> 92<th> 93 <p> 94 GNU C++ version 7.1.0<br> linux<br> double 95 </p> 96 </th> 97<th> 98 <p> 99 GNU C++ version 7.1.0<br> linux<br> long double 100 </p> 101 </th> 102<th> 103 <p> 104 Sun compiler version 0x5150<br> Sun Solaris<br> long double 105 </p> 106 </th> 107<th> 108 <p> 109 Microsoft Visual C++ version 14.1<br> Win32<br> double 110 </p> 111 </th> 112</tr></thead> 113<tbody><tr> 114<td> 115 <p> 116 sqrt1pm1 117 </p> 118 </td> 119<td> 120 <p> 121 <span class="blue">Max = 1.3ε (Mean = 0.404ε)</span> 122 </p> 123 </td> 124<td> 125 <p> 126 <span class="blue">Max = 1.33ε (Mean = 0.404ε)</span> 127 </p> 128 </td> 129<td> 130 <p> 131 <span class="blue">Max = 1.54ε (Mean = 0.563ε)</span> 132 </p> 133 </td> 134<td> 135 <p> 136 <span class="blue">Max = 1.35ε (Mean = 0.497ε)</span> 137 </p> 138 </td> 139</tr></tbody> 140</table></div> 141</div> 142<br class="table-break"><h5> 143<a name="math_toolkit.powers.sqrt1pm1.h1"></a> 144 <span class="phrase"><a name="math_toolkit.powers.sqrt1pm1.testing"></a></span><a class="link" href="sqrt1pm1.html#math_toolkit.powers.sqrt1pm1.testing">Testing</a> 145 </h5> 146<p> 147 A selection of random high precision test values calculated using NTL::RR 148 at 1000-bit precision. 149 </p> 150</div> 151<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 152<td align="left"></td> 153<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 154 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 155 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 156 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 157 Daryle Walker and Xiaogang Zhang<p> 158 Distributed under the Boost Software License, Version 1.0. (See accompanying 159 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>) 160 </p> 161</div></td> 162</tr></table> 163<hr> 164<div class="spirit-nav"> 165<a accesskey="p" href="cbrt.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="powm1.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 166</div> 167</body> 168</html> 169