mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-24 22:02:20 +08:00
Documentation for 341ed50da8
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
||||
<meta name="generator" content="Doxygen 1.9.1"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
||||
<meta name="generator" content="Doxygen 1.9.2"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>Algorithms_in_C++: math/inv_sqrt.cpp File Reference</title>
|
||||
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
||||
@@ -17,9 +17,9 @@
|
||||
<script type="text/javascript" src="../../search/searchdata.js"></script>
|
||||
<script type="text/javascript" src="../../search/search.js"></script>
|
||||
<script type="text/x-mathjax-config">
|
||||
MathJax.Hub.Config({
|
||||
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
|
||||
jax: ["input/TeX","output/HTML-CSS"],
|
||||
MathJax.Hub.Config({
|
||||
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
|
||||
jax: ["input/TeX","output/HTML-CSS"],
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
|
||||
@@ -32,8 +32,7 @@
|
||||
<tbody>
|
||||
<tr style="height: 56px;">
|
||||
<td id="projectalign" style="padding-left: 0.5em;">
|
||||
<div id="projectname">Algorithms_in_C++
|
||||
 <span id="projectnumber">1.0.0</span>
|
||||
<div id="projectname">Algorithms_in_C++<span id="projectnumber"> 1.0.0</span>
|
||||
</div>
|
||||
<div id="projectbrief">Set of algorithms implemented in C++.</div>
|
||||
</td>
|
||||
@@ -42,21 +41,22 @@
|
||||
</table>
|
||||
</div>
|
||||
<!-- end header part -->
|
||||
<!-- Generated by Doxygen 1.9.1 -->
|
||||
<!-- Generated by Doxygen 1.9.2 -->
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
||||
var searchBox = new SearchBox("searchBox", "../../search",false,'Search','.html');
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
|
||||
/* @license-end */
|
||||
</script>
|
||||
<script type="text/javascript" src="../../menudata.js"></script>
|
||||
<script type="text/javascript" src="../../menu.js"></script>
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
$(function() {
|
||||
initMenu('../../',true,false,'search.php','Search');
|
||||
$(document).ready(function() { init_search(); });
|
||||
});
|
||||
/* @license-end */</script>
|
||||
/* @license-end */
|
||||
</script>
|
||||
<div id="main-nav"></div>
|
||||
</div><!-- top -->
|
||||
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
||||
@@ -70,7 +70,7 @@ $(function() {
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
||||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
||||
$(document).ready(function(){initNavTree('d6/db8/inv__sqrt_8cpp.html','../../'); initResizable(); });
|
||||
/* @license-end */
|
||||
</script>
|
||||
@@ -92,12 +92,11 @@ $(document).ready(function(){initNavTree('d6/db8/inv__sqrt_8cpp.html','../../');
|
||||
<div class="header">
|
||||
<div class="summary">
|
||||
<a href="#func-members">Functions</a> </div>
|
||||
<div class="headertitle">
|
||||
<div class="title">inv_sqrt.cpp File Reference</div> </div>
|
||||
<div class="headertitle"><div class="title">inv_sqrt.cpp File Reference</div></div>
|
||||
</div><!--header-->
|
||||
<div class="contents">
|
||||
|
||||
<p>Implementation of <a href="https://medium.com/hard-mode/the-legendary-fast-inverse-square-root-e51fee3b49d9">the inverse square root Root</a>.
|
||||
<p>Implementation of <a href="https://medium.com/hard-mode/the-legendary-fast-inverse-square-root-e51fee3b49d9" target="_blank">the inverse square root Root</a>.
|
||||
<a href="#details">More...</a></p>
|
||||
<div class="textblock"><code>#include <cassert></code><br />
|
||||
<code>#include <cmath></code><br />
|
||||
@@ -110,7 +109,7 @@ Include dependency graph for inv_sqrt.cpp:</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><table class="memberdecls">
|
||||
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
|
||||
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
||||
Functions</h2></td></tr>
|
||||
<tr class="memitem:ad219034bf5fba657f5035ec5a1d50f52"><td class="memTemplParams" colspan="2">template<typename T = double, char iterations = 2> </td></tr>
|
||||
<tr class="memitem:ad219034bf5fba657f5035ec5a1d50f52"><td class="memTemplItemLeft" align="right" valign="top">T </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="../../d6/db8/inv__sqrt_8cpp.html#ad219034bf5fba657f5035ec5a1d50f52">Fast_InvSqrt</a> (T x)</td></tr>
|
||||
@@ -118,7 +117,7 @@ Functions</h2></td></tr>
|
||||
<tr class="separator:ad219034bf5fba657f5035ec5a1d50f52"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:aa2703e5cf3fecde8becd9066b9666b97"><td class="memTemplParams" colspan="2">template<typename T = double> </td></tr>
|
||||
<tr class="memitem:aa2703e5cf3fecde8becd9066b9666b97"><td class="memTemplItemLeft" align="right" valign="top">T </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="../../d6/db8/inv__sqrt_8cpp.html#aa2703e5cf3fecde8becd9066b9666b97">Standard_InvSqrt</a> (T number)</td></tr>
|
||||
<tr class="memdesc:aa2703e5cf3fecde8becd9066b9666b97"><td class="mdescLeft"> </td><td class="mdescRight">This is the function that calculates the fast inverse square root. The following code is the fast inverse square root with standard lib (cmath) More information can be found at <a href="https://www.linkedin.com/pulse/fast-inverse-square-root-still-armin-kassemi-langroodi">LinkedIn</a> <a href="../../d6/db8/inv__sqrt_8cpp.html#aa2703e5cf3fecde8becd9066b9666b97">More...</a><br /></td></tr>
|
||||
<tr class="memdesc:aa2703e5cf3fecde8becd9066b9666b97"><td class="mdescLeft"> </td><td class="mdescRight">This is the function that calculates the fast inverse square root. The following code is the fast inverse square root with standard lib (cmath) More information can be found at <a href="https://www.linkedin.com/pulse/fast-inverse-square-root-still-armin-kassemi-langroodi" target="_blank">LinkedIn</a> <a href="../../d6/db8/inv__sqrt_8cpp.html#aa2703e5cf3fecde8becd9066b9666b97">More...</a><br /></td></tr>
|
||||
<tr class="separator:aa2703e5cf3fecde8becd9066b9666b97"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d6/db8/inv__sqrt_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
|
||||
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">Self-test implementations. <a href="../../d6/db8/inv__sqrt_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">More...</a><br /></td></tr>
|
||||
@@ -128,10 +127,10 @@ Functions</h2></td></tr>
|
||||
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
</table>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p>Implementation of <a href="https://medium.com/hard-mode/the-legendary-fast-inverse-square-root-e51fee3b49d9">the inverse square root Root</a>. </p>
|
||||
<p>Two implementation to calculate inverse inverse root, from Quake III Arena (C++ version) and with a standard library (<code>cmath</code>). This algorithm is used to calculate shadows in Quake III Arena. </p>
|
||||
<div class="textblock"><p >Implementation of <a href="https://medium.com/hard-mode/the-legendary-fast-inverse-square-root-e51fee3b49d9" target="_blank">the inverse square root Root</a>. </p>
|
||||
<p >Two implementation to calculate inverse inverse root, from Quake III Arena (C++ version) and with a standard library (<code>cmath</code>). This algorithm is used to calculate shadows in Quake III Arena. </p>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
<a id="ad219034bf5fba657f5035ec5a1d50f52"></a>
|
||||
<a id="ad219034bf5fba657f5035ec5a1d50f52" name="ad219034bf5fba657f5035ec5a1d50f52"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#ad219034bf5fba657f5035ec5a1d50f52">◆ </a></span>Fast_InvSqrt()</h2>
|
||||
|
||||
<div class="memitem">
|
||||
@@ -158,8 +157,8 @@ template<typename T = double, char iterations = 2> </div>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>for numeric_limits </p>
|
||||
<p>for assert for <code><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/sqrt.html">std::sqrt</a></code> for IO operations</p>
|
||||
<p>This is the function that calculates the fast inverse square root. The following code is the fast inverse square root implementation from Quake III Arena (Adapted for C++). More information can be found at <a href="https://en.wikipedia.org/wiki/Fast_inverse_square_root">Wikipedia</a> </p><dl class="tparams"><dt>Template Parameters</dt><dd>
|
||||
<p >for assert for <code><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/sqrt.html">std::sqrt</a></code> for IO operations</p>
|
||||
<p >This is the function that calculates the fast inverse square root. The following code is the fast inverse square root implementation from Quake III Arena (Adapted for C++). More information can be found at <a href="https://en.wikipedia.org/wiki/Fast_inverse_square_root" target="_blank">Wikipedia</a> </p><dl class="tparams"><dt>Template Parameters</dt><dd>
|
||||
<table class="tparams">
|
||||
<tr><td class="paramname">T</td><td>floating type </td></tr>
|
||||
<tr><td class="paramname">iterations</td><td>inverse square root, the greater the number of iterations, the more exact the result will be (1 or 2). </td></tr>
|
||||
@@ -173,32 +172,32 @@ template<typename T = double, char iterations = 2> </div>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="section return"><dt>Returns</dt><dd>the inverse square root </dd></dl>
|
||||
<div class="fragment"><div class="line"><a name="l00028"></a><span class="lineno"> 28</span>  {</div>
|
||||
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span>  <span class="keyword">using</span> Tint = <span class="keyword">typename</span> <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/types/conditional.html">std::conditional</a><<span class="keyword">sizeof</span>(T) == 8, <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/types/integer.html">std::int64_t</a>,</div>
|
||||
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/types/integer.html">std::int32_t</a>>::type;</div>
|
||||
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span>  T y = x;</div>
|
||||
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span>  T x2 = y * 0.5;</div>
|
||||
<div class="line"><a name="l00033"></a><span class="lineno"> 33</span>  </div>
|
||||
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span>  Tint i =</div>
|
||||
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span>  *<span class="keyword">reinterpret_cast<</span>Tint *<span class="keyword">></span>(&y); <span class="comment">// Store floating-point bits in integer</span></div>
|
||||
<div class="line"><a name="l00036"></a><span class="lineno"> 36</span>  </div>
|
||||
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  i = (<span class="keyword">sizeof</span>(T) == 8 ? 0x5fe6eb50c7b537a9 : 0x5f3759df) -</div>
|
||||
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  (i >> 1); <span class="comment">// Initial guess for Newton's method</span></div>
|
||||
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span>  </div>
|
||||
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  y = *<span class="keyword">reinterpret_cast<</span>T *<span class="keyword">></span>(&i); <span class="comment">// Convert new bits into float</span></div>
|
||||
<div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  </div>
|
||||
<div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  y = y * (1.5 - (x2 * y * y)); <span class="comment">// 1st iteration Newton's method</span></div>
|
||||
<div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  <span class="keywordflow">if</span> (iterations == 2) {</div>
|
||||
<div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  y = y * (1.5 - (x2 * y * y)); <span class="comment">// 2nd iteration, the more exact result</span></div>
|
||||
<div class="line"><a name="l00045"></a><span class="lineno"> 45</span>  }</div>
|
||||
<div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  <span class="keywordflow">return</span> y;</div>
|
||||
<div class="line"><a name="l00047"></a><span class="lineno"> 47</span> }</div>
|
||||
<div class="fragment"><div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span> {</div>
|
||||
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> <span class="keyword">using</span> Tint = <span class="keyword">typename</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/types/conditional.html">std::conditional</a><<span class="keyword">sizeof</span>(T) == 8, <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/types/integer.html">std::int64_t</a>,</div>
|
||||
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/types/integer.html">std::int32_t</a>>::type;</div>
|
||||
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> T y = x;</div>
|
||||
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> T x2 = y * 0.5;</div>
|
||||
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> </div>
|
||||
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span> Tint i =</div>
|
||||
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span> *<span class="keyword">reinterpret_cast<</span>Tint *<span class="keyword">></span>(&y); <span class="comment">// Store floating-point bits in integer</span></div>
|
||||
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> </div>
|
||||
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> i = (<span class="keyword">sizeof</span>(T) == 8 ? 0x5fe6eb50c7b537a9 : 0x5f3759df) -</div>
|
||||
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> (i >> 1); <span class="comment">// Initial guess for Newton's method</span></div>
|
||||
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> </div>
|
||||
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> y = *<span class="keyword">reinterpret_cast<</span>T *<span class="keyword">></span>(&i); <span class="comment">// Convert new bits into float</span></div>
|
||||
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span> </div>
|
||||
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> y = y * (1.5 - (x2 * y * y)); <span class="comment">// 1st iteration Newton's method</span></div>
|
||||
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> <span class="keywordflow">if</span> (iterations == 2) {</div>
|
||||
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> y = y * (1.5 - (x2 * y * y)); <span class="comment">// 2nd iteration, the more exact result</span></div>
|
||||
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> }</div>
|
||||
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> <span class="keywordflow">return</span> y;</div>
|
||||
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span>}</div>
|
||||
<div class="ttc" id="aconditional_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/types/conditional.html">std::conditional</a></div></div>
|
||||
<div class="ttc" id="ainteger_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/types/integer.html">std::int64_t</a></div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
||||
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">◆ </a></span>main()</h2>
|
||||
|
||||
<div class="memitem">
|
||||
@@ -216,23 +215,23 @@ template<typename T = double, char iterations = 2> </div>
|
||||
|
||||
<p>Main function. </p>
|
||||
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
|
||||
<div class="fragment"><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  {</div>
|
||||
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  <a class="code" href="../../d6/db8/inv__sqrt_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// run self-test implementations</span></div>
|
||||
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The Fast inverse square root of 36 is: "</span></div>
|
||||
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  << Fast_InvSqrt<float, 1>(36.0f) << <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The Fast inverse square root of 36 is: "</span></div>
|
||||
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  << Fast_InvSqrt<double, 2>(36.0f) << <span class="stringliteral">" (2 iterations)"</span></div>
|
||||
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  << <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The Fast inverse square root of 100 is: "</span></div>
|
||||
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  << <a class="code" href="../../d6/db8/inv__sqrt_8cpp.html#ad219034bf5fba657f5035ec5a1d50f52">Fast_InvSqrt</a>(100.0f)</div>
|
||||
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  << <span class="stringliteral">" (With default template type and iterations: double, 2)"</span></div>
|
||||
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  << <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The Standard inverse square root of 36 is: "</span></div>
|
||||
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  << Standard_InvSqrt<float>(36.0f) << <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The Standard inverse square root of 100 is: "</span></div>
|
||||
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  << <a class="code" href="../../d6/db8/inv__sqrt_8cpp.html#aa2703e5cf3fecde8becd9066b9666b97">Standard_InvSqrt</a>(100.0f)</div>
|
||||
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  << <span class="stringliteral">" (With default template type: double)"</span> << <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span> }</div>
|
||||
<div class="fragment"><div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> {</div>
|
||||
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span> <a class="code hl_function" href="../../d6/db8/inv__sqrt_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// run self-test implementations</span></div>
|
||||
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno"> 89</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The Fast inverse square root of 36 is: "</span></div>
|
||||
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno"> 90</span> << Fast_InvSqrt<float, 1>(36.0f) << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno"> 91</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The Fast inverse square root of 36 is: "</span></div>
|
||||
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno"> 92</span> << Fast_InvSqrt<double, 2>(36.0f) << <span class="stringliteral">" (2 iterations)"</span></div>
|
||||
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"> 93</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The Fast inverse square root of 100 is: "</span></div>
|
||||
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> << <a class="code hl_function" href="../../d6/db8/inv__sqrt_8cpp.html#ad219034bf5fba657f5035ec5a1d50f52">Fast_InvSqrt</a>(100.0f)</div>
|
||||
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> << <span class="stringliteral">" (With default template type and iterations: double, 2)"</span></div>
|
||||
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The Standard inverse square root of 36 is: "</span></div>
|
||||
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> << Standard_InvSqrt<float>(36.0f) << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"The Standard inverse square root of 100 is: "</span></div>
|
||||
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span> << <a class="code hl_function" href="../../d6/db8/inv__sqrt_8cpp.html#aa2703e5cf3fecde8becd9066b9666b97">Standard_InvSqrt</a>(100.0f)</div>
|
||||
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> << <span class="stringliteral">" (With default template type: double)"</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span>}</div>
|
||||
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
|
||||
<div class="ttc" id="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(T... args)</div></div>
|
||||
<div class="ttc" id="ainv__sqrt_8cpp_html_aa2703e5cf3fecde8becd9066b9666b97"><div class="ttname"><a href="../../d6/db8/inv__sqrt_8cpp.html#aa2703e5cf3fecde8becd9066b9666b97">Standard_InvSqrt</a></div><div class="ttdeci">T Standard_InvSqrt(T number)</div><div class="ttdoc">This is the function that calculates the fast inverse square root. The following code is the fast inv...</div><div class="ttdef"><b>Definition:</b> inv_sqrt.cpp:59</div></div>
|
||||
@@ -247,7 +246,7 @@ Here is the call graph for this function:</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<a id="aa2703e5cf3fecde8becd9066b9666b97"></a>
|
||||
<a id="aa2703e5cf3fecde8becd9066b9666b97" name="aa2703e5cf3fecde8becd9066b9666b97"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#aa2703e5cf3fecde8becd9066b9666b97">◆ </a></span>Standard_InvSqrt()</h2>
|
||||
|
||||
<div class="memitem">
|
||||
@@ -265,7 +264,7 @@ template<typename T = double> </div>
|
||||
</table>
|
||||
</div><div class="memdoc">
|
||||
|
||||
<p>This is the function that calculates the fast inverse square root. The following code is the fast inverse square root with standard lib (cmath) More information can be found at <a href="https://www.linkedin.com/pulse/fast-inverse-square-root-still-armin-kassemi-langroodi">LinkedIn</a> </p>
|
||||
<p>This is the function that calculates the fast inverse square root. The following code is the fast inverse square root with standard lib (cmath) More information can be found at <a href="https://www.linkedin.com/pulse/fast-inverse-square-root-still-armin-kassemi-langroodi" target="_blank">LinkedIn</a> </p>
|
||||
<dl class="tparams"><dt>Template Parameters</dt><dd>
|
||||
<table class="tparams">
|
||||
<tr><td class="paramname">T</td><td>floating type </td></tr>
|
||||
@@ -279,15 +278,15 @@ template<typename T = double> </div>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="section return"><dt>Returns</dt><dd>the inverse square root </dd></dl>
|
||||
<div class="fragment"><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  {</div>
|
||||
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  T squareRoot = <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/sqrt.html">sqrt</a>(number);</div>
|
||||
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  <span class="keywordflow">return</span> 1.0f / squareRoot;</div>
|
||||
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span> }</div>
|
||||
<div class="fragment"><div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> {</div>
|
||||
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> T squareRoot = <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/sqrt.html">sqrt</a>(number);</div>
|
||||
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> <span class="keywordflow">return</span> 1.0f / squareRoot;</div>
|
||||
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span>}</div>
|
||||
<div class="ttc" id="asqrt_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/numeric/math/sqrt.html">std::sqrt</a></div><div class="ttdeci">T sqrt(T... args)</div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="aa8dca7b867074164d5f45b0f3851269d"></a>
|
||||
<a id="aa8dca7b867074164d5f45b0f3851269d" name="aa8dca7b867074164d5f45b0f3851269d"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#aa8dca7b867074164d5f45b0f3851269d">◆ </a></span>test()</h2>
|
||||
|
||||
<div class="memitem">
|
||||
@@ -312,20 +311,20 @@ template<typename T = double> </div>
|
||||
|
||||
<p>Self-test implementations. </p>
|
||||
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
||||
<div class="fragment"><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  {</div>
|
||||
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  <span class="keyword">const</span> <span class="keywordtype">float</span> epsilon = 1e-3f;</div>
|
||||
<div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  </div>
|
||||
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  <span class="comment">/* Tests with multiple values */</span></div>
|
||||
<div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  assert(<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Standard_InvSqrt<float>(100.0f) - 0.0998449f) < epsilon);</div>
|
||||
<div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  assert(<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Standard_InvSqrt<double>(36.0f) - 0.166667f) < epsilon);</div>
|
||||
<div class="line"><a name="l00074"></a><span class="lineno"> 74</span>  assert(<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(<a class="code" href="../../d6/db8/inv__sqrt_8cpp.html#aa2703e5cf3fecde8becd9066b9666b97">Standard_InvSqrt</a>(12.0f) - 0.288423f) < epsilon);</div>
|
||||
<div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  assert(<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Standard_InvSqrt<double>(5.0f) - 0.447141f) < epsilon);</div>
|
||||
<div class="line"><a name="l00076"></a><span class="lineno"> 76</span>  </div>
|
||||
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  assert(<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Fast_InvSqrt<float, 1>(100.0f) - 0.0998449f) < epsilon);</div>
|
||||
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  assert(<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Fast_InvSqrt<double, 1>(36.0f) - 0.166667f) < epsilon);</div>
|
||||
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  assert(<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(<a class="code" href="../../d6/db8/inv__sqrt_8cpp.html#ad219034bf5fba657f5035ec5a1d50f52">Fast_InvSqrt</a>(12.0f) - 0.288423) < epsilon);</div>
|
||||
<div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  assert(<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Fast_InvSqrt<double>(5.0f) - 0.447141) < epsilon);</div>
|
||||
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span> }</div>
|
||||
<div class="fragment"><div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> {</div>
|
||||
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> <span class="keyword">const</span> <span class="keywordtype">float</span> epsilon = 1e-3f;</div>
|
||||
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> </div>
|
||||
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> <span class="comment">/* Tests with multiple values */</span></div>
|
||||
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> assert(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Standard_InvSqrt<float>(100.0f) - 0.0998449f) < epsilon);</div>
|
||||
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> assert(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Standard_InvSqrt<double>(36.0f) - 0.166667f) < epsilon);</div>
|
||||
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> assert(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(<a class="code hl_function" href="../../d6/db8/inv__sqrt_8cpp.html#aa2703e5cf3fecde8becd9066b9666b97">Standard_InvSqrt</a>(12.0f) - 0.288423f) < epsilon);</div>
|
||||
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> assert(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Standard_InvSqrt<double>(5.0f) - 0.447141f) < epsilon);</div>
|
||||
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> </div>
|
||||
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> assert(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Fast_InvSqrt<float, 1>(100.0f) - 0.0998449f) < epsilon);</div>
|
||||
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> assert(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Fast_InvSqrt<double, 1>(36.0f) - 0.166667f) < epsilon);</div>
|
||||
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> assert(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(<a class="code hl_function" href="../../d6/db8/inv__sqrt_8cpp.html#ad219034bf5fba657f5035ec5a1d50f52">Fast_InvSqrt</a>(12.0f) - 0.288423) < epsilon);</div>
|
||||
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> assert(<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a>(Fast_InvSqrt<double>(5.0f) - 0.447141) < epsilon);</div>
|
||||
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span>}</div>
|
||||
<div class="ttc" id="afabs_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/numeric/math/fabs.html">std::fabs</a></div><div class="ttdeci">T fabs(T... args)</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
@@ -342,7 +341,7 @@ Here is the call graph for this function:</div>
|
||||
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||||
<ul>
|
||||
<li class="navelem"><a class="el" href="../../dir_296d53ceaeaa7e099814a6def439fe8a.html">math</a></li><li class="navelem"><a class="el" href="../../d6/db8/inv__sqrt_8cpp.html">inv_sqrt.cpp</a></li>
|
||||
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
|
||||
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2 </li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user