Documentation for 8b1eab204b

This commit is contained in:
realstealthninja
2024-11-04 12:43:05 +00:00
parent 4fb6e622e9
commit a7bccf7d01
6732 changed files with 153919 additions and 365711 deletions

View File

@@ -1,3 +1,4 @@
<!-- HTML header for doxygen 1.12.0-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
@@ -5,10 +6,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: math/approximate_pi.cpp File Reference</title>
<title>TheAlgorithms/C++: math/approximate_pi.cpp File Reference</title>
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript">
DoxygenAwesomeDarkModeToggle.init()
</script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../navtreedata.js"></script>
@@ -18,14 +24,24 @@
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<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"],
});
<script type="text/javascript">
window.MathJax = {
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
},
loader: {
load: ['[tex]/ams']
},
tex: {
macros: {},
packages: ['base','configmacros','ams']
}
};
</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>
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
@@ -33,10 +49,11 @@ MathJax.Hub.Config({
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
<td id="projectalign">
<div id="projectname">Algorithms_in_C++<span id="projectnumber">&#160;1.0.0</span>
<div id="projectname">TheAlgorithms/C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C++.</div>
<div id="projectbrief">All the algorithms implemented in C++</div>
</td>
</tr>
</tbody>
@@ -123,7 +140,9 @@ Include dependency graph for approximate_pi.cpp:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d2/d27/approximate__pi_8cpp__incl.svg" width="335" height="111"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div><table class="memberdecls">
</div>
<p><a href="../../d0/d51/approximate__pi_8cpp_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="namespaces" name="namespaces"></a>
Namespaces</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">namespace &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d47/namespacemath.html">math</a></td></tr>
@@ -138,7 +157,7 @@ Typedefs</h2></td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:abf7f2a6d91f1ca6c89698792aea3f188" id="r_abf7f2a6d91f1ca6c89698792aea3f188"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d47/namespacemath.html#abf7f2a6d91f1ca6c89698792aea3f188">math::approximate_pi</a> (const <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a>&lt; <a class="el" href="../../dd/d47/namespacemath.html#a006c8ebd11bb1e035815dc835a1a7a85">Point</a> &gt; &amp;pts)</td></tr>
<tr class="memitem:abf7f2a6d91f1ca6c89698792aea3f188" id="r_abf7f2a6d91f1ca6c89698792aea3f188"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d47/namespacemath.html#abf7f2a6d91f1ca6c89698792aea3f188">math::approximate_pi</a> (const std::vector&lt; <a class="el" href="../../dd/d47/namespacemath.html#a006c8ebd11bb1e035815dc835a1a7a85">Point</a> &gt; &amp;pts)</td></tr>
<tr class="memdesc:abf7f2a6d91f1ca6c89698792aea3f188"><td class="mdescLeft">&#160;</td><td class="mdescRight">This function uses the points in a given vector 'pts' (drawn at random) to return an approximation of the number π. <br /></td></tr>
<tr class="separator:abf7f2a6d91f1ca6c89698792aea3f188"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a483bb8ccf42aaf7375a83e91490eda1e" id="r_a483bb8ccf42aaf7375a83e91490eda1e"><td class="memItemLeft" align="right" valign="top">static void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a483bb8ccf42aaf7375a83e91490eda1e">tests</a> ()</td></tr>
@@ -152,6 +171,8 @@ Functions</h2></td></tr>
<div class="textblock"><p>Implementation to calculate an estimate of the <a href="https://en.wikipedia.org/wiki/File:Pi_30K.gif" target="_blank">number π (Pi)</a>. </p>
<p>We take a random point P with coordinates (x, y) such that 0 ≤ x ≤ 1 and 0 ≤ y ≤ 1. If x² + y² ≤ 1, then the point is inside the quarter disk of radius 1, else the point is outside. We know that the probability of the point being inside the quarter disk is equal to π/4 double approx(vector&lt;Point&gt; &amp;pts) which will use the points pts (drawn at random) to return an estimate of the number π </p><dl class="section note"><dt>Note</dt><dd>This implementation is better than naive recursive or iterative approach.</dd></dl>
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/Qannaf" target="_blank">Qannaf AL-SAHMI</a> </dd></dl>
<p class="definition">Definition in file <a class="el" href="../../d0/d51/approximate__pi_8cpp_source.html">approximate_pi.cpp</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">&#9670;&#160;</a></span>main()</h2>
@@ -170,17 +191,14 @@ Functions</h2></td></tr>
<p>Main function. </p>
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d0/d51/approximate__pi_8cpp_source.html#l00080">80</a> of file <a class="el" href="../../d0/d51/approximate__pi_8cpp_source.html">approximate_pi.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 80</span> {</div>
<div class="line"><span class="lineno"> 81</span> <a class="code hl_function" href="#a483bb8ccf42aaf7375a83e91490eda1e">tests</a>(); <span class="comment">// run self-test implementations</span></div>
<div class="line"><span class="lineno"> 82</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 83</span>}</div>
<div class="ttc" id="aapproximate__pi_8cpp_html_a483bb8ccf42aaf7375a83e91490eda1e"><div class="ttname"><a href="#a483bb8ccf42aaf7375a83e91490eda1e">tests</a></div><div class="ttdeci">static void tests()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition</b> approximate_pi.cpp:62</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d0/d51/approximate__pi_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="524" height="135"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
<div class="ttc" id="aapproximate__pi_8cpp_html_a483bb8ccf42aaf7375a83e91490eda1e"><div class="ttname"><a href="#a483bb8ccf42aaf7375a83e91490eda1e">tests</a></div><div class="ttdeci">static void tests()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition</b> <a href="../../d0/d51/approximate__pi_8cpp_source.html#l00062">approximate_pi.cpp:62</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a483bb8ccf42aaf7375a83e91490eda1e" name="a483bb8ccf42aaf7375a83e91490eda1e"></a>
@@ -208,32 +226,24 @@ Here is the call graph for this function:</div>
<p>Self-test implementations. </p>
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
<p class="definition">Definition at line <a class="el" href="../../d0/d51/approximate__pi_8cpp_source.html#l00062">62</a> of file <a class="el" href="../../d0/d51/approximate__pi_8cpp_source.html">approximate_pi.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 62</span> {</div>
<div class="line"><span class="lineno"> 63</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;math::Point&gt;</a> rands;</div>
<div class="line"><span class="lineno"> 64</span> <span class="keywordflow">for</span> (<a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/types/size_t.html">std::size_t</a> i = 0; i &lt; 100000; i++) {</div>
<div class="line"><span class="lineno"> 63</span> std::vector&lt;math::Point&gt; rands;</div>
<div class="line"><span class="lineno"> 64</span> <span class="keywordflow">for</span> (std::size_t i = 0; i &lt; 100000; i++) {</div>
<div class="line"><span class="lineno"> 65</span> <a class="code hl_typedef" href="../../dd/d47/namespacemath.html#a006c8ebd11bb1e035815dc835a1a7a85">math::Point</a> p;</div>
<div class="line"><span class="lineno"> 66</span> p.x = rand() / <span class="keyword">static_cast&lt;</span><span class="keywordtype">double</span><span class="keyword">&gt;</span>(RAND_MAX); <span class="comment">// 0 &lt;= x &lt;= 1</span></div>
<div class="line"><span class="lineno"> 67</span> p.y = rand() / <span class="keyword">static_cast&lt;</span><span class="keywordtype">double</span><span class="keyword">&gt;</span>(RAND_MAX); <span class="comment">// 0 &lt;= y &lt;= 1</span></div>
<div class="line"><span class="lineno"> 68</span> rands.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/push_back.html">push_back</a>(p);</div>
<div class="line"><span class="lineno"> 68</span> rands.push_back(p);</div>
<div class="line"><span class="lineno"> 69</span> }</div>
<div class="line"><span class="lineno"> 70</span> assert(<a class="code hl_function" href="../../dd/d47/namespacemath.html#abf7f2a6d91f1ca6c89698792aea3f188">math::approximate_pi</a>(rands) &gt; 3.135);</div>
<div class="line"><span class="lineno"> 71</span> assert(<a class="code hl_function" href="../../dd/d47/namespacemath.html#abf7f2a6d91f1ca6c89698792aea3f188">math::approximate_pi</a>(rands) &lt; 3.145);</div>
<div class="line"><span class="lineno"> 72</span> </div>
<div class="line"><span class="lineno"> 73</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;All tests have successfully passed!&quot;</span> &lt;&lt; <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"><span class="lineno"> 73</span> std::cout &lt;&lt; <span class="stringliteral">&quot;All tests have successfully passed!&quot;</span> &lt;&lt; std::endl;</div>
<div class="line"><span class="lineno"> 74</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="anamespacemath_html_a006c8ebd11bb1e035815dc835a1a7a85"><div class="ttname"><a href="../../dd/d47/namespacemath.html#a006c8ebd11bb1e035815dc835a1a7a85">math::Point</a></div><div class="ttdeci">struct { double x; double y;} Point</div><div class="ttdoc">structure of points containing two numbers, x and y, such that 0 ≤ x ≤ 1 and 0 ≤ y ≤ 1.</div><div class="ttdef"><b>Definition</b> approximate_pi.cpp:35</div></div>
<div class="ttc" id="anamespacemath_html_abf7f2a6d91f1ca6c89698792aea3f188"><div class="ttname"><a href="../../dd/d47/namespacemath.html#abf7f2a6d91f1ca6c89698792aea3f188">math::approximate_pi</a></div><div class="ttdeci">double approximate_pi(const std::vector&lt; Point &gt; &amp;pts)</div><div class="ttdoc">This function uses the points in a given vector 'pts' (drawn at random) to return an approximation of...</div><div class="ttdef"><b>Definition</b> approximate_pi.cpp:47</div></div>
<div class="ttc" id="apush_back_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector/push_back.html">std::vector::push_back</a></div><div class="ttdeci">T push_back(T... args)</div></div>
<div class="ttc" id="asize_t_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/types/size_t.html">std::size_t</a></div></div>
<div class="ttc" id="avector_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a></div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d0/d51/approximate__pi_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.svg" width="427" height="135"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
<div class="ttc" id="anamespacemath_html_a006c8ebd11bb1e035815dc835a1a7a85"><div class="ttname"><a href="../../dd/d47/namespacemath.html#a006c8ebd11bb1e035815dc835a1a7a85">math::Point</a></div><div class="ttdeci">struct { double x; double y;} Point</div><div class="ttdoc">structure of points containing two numbers, x and y, such that 0 ≤ x ≤ 1 and 0 ≤ y ≤ 1.</div><div class="ttdef"><b>Definition</b> <a href="../../d0/d51/approximate__pi_8cpp_source.html#l00035">approximate_pi.cpp:35</a></div></div>
<div class="ttc" id="anamespacemath_html_abf7f2a6d91f1ca6c89698792aea3f188"><div class="ttname"><a href="../../dd/d47/namespacemath.html#abf7f2a6d91f1ca6c89698792aea3f188">math::approximate_pi</a></div><div class="ttdeci">double approximate_pi(const std::vector&lt; Point &gt; &amp;pts)</div><div class="ttdoc">This function uses the points in a given vector 'pts' (drawn at random) to return an approximation of...</div><div class="ttdef"><b>Definition</b> <a href="../../d0/d51/approximate__pi_8cpp_source.html#l00047">approximate_pi.cpp:47</a></div></div>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->