• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>hypot</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="powm1.html" title="powm1">
10<link rel="next" href="ct_pow.html" title="Compile Time Power of a Runtime Base">
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="powm1.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="ct_pow.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.hypot"></a><a class="link" href="hypot.html" title="hypot">hypot</a>
28</h3></div></div></div>
29<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
30<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">hypot</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">y</span><span class="special">);</span>
31
32<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</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">&gt;</span>
33<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">hypot</span><span class="special">(</span><span class="identifier">T1</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">T2</span> <span class="identifier">y</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">&amp;);</span>
34</pre>
35<p>
36        <span class="bold"><strong>Effects: </strong></span> computes
37      </p>
38<div class="blockquote"><blockquote class="blockquote"><p>
39          <span class="inlinemediaobject"><img src="../../../equations/hypot.svg"></span>
40
41        </p></blockquote></div>
42<p>
43        in such a way as to avoid undue underflow and overflow.
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> when T1 and T2 are of different
48        types.
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        When calculating
58      </p>
59<div class="blockquote"><blockquote class="blockquote"><p>
60          <span class="inlinemediaobject"><img src="../../../equations/hypot.svg"></span>
61
62        </p></blockquote></div>
63<p>
64        it's quite easy for the intermediate terms to either overflow or underflow,
65        even though the result is in fact perfectly representable.
66      </p>
67<h5>
68<a name="math_toolkit.powers.hypot.h0"></a>
69        <span class="phrase"><a name="math_toolkit.powers.hypot.implementation"></a></span><a class="link" href="hypot.html#math_toolkit.powers.hypot.implementation">Implementation</a>
70      </h5>
71<p>
72        The function is even and symmetric in <span class="emphasis"><em>x</em></span> and <span class="emphasis"><em>y</em></span>,
73        so first take assume <span class="emphasis"><em>x,y &gt; 0</em></span> and <span class="emphasis"><em>x &gt;
74        y</em></span> (we can permute the arguments if this is not the case).
75      </p>
76<p>
77        Then if <span class="emphasis"><em>x * ε &gt;= y</em></span> we can simply return <span class="emphasis"><em>x</em></span>.
78      </p>
79<p>
80        Otherwise the result is given by:
81      </p>
82<div class="blockquote"><blockquote class="blockquote"><p>
83          <span class="inlinemediaobject"><img src="../../../equations/hypot2.svg"></span>
84
85        </p></blockquote></div>
86</div>
87<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
88<td align="left"></td>
89<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
90      Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
91      Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
92      Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
93      Daryle Walker and Xiaogang Zhang<p>
94        Distributed under the Boost Software License, Version 1.0. (See accompanying
95        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>)
96      </p>
97</div></td>
98</tr></table>
99<hr>
100<div class="spirit-nav">
101<a accesskey="p" href="powm1.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="ct_pow.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
102</div>
103</body>
104</html>
105