Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Finally I have implemented the <code>sin</code> metafunction through Taylor series, using series of 10 terms by default (Could be configurable). I have based my implementation in <a href="https://web.archive.org/web/20131010041400/http://www10.informatik.uni-erlangen.de/~pflaum/pflaum/ProSeminar/meta-art.html" rel="nofollow noreferrer">this interesting article</a>. </p> <p>My library includes an implementation of a tmp for loop using iterators, and <a href="https://stackoverflow.com/questions/18688678/disabling-operators-overloads-if-a-given-template-is-not-specialized-for-the-ope">expression templates to allow write complex expressions in a "clear" way</a> (Clear compared to the common template-meta-programming syntax <code>add&lt;mul&lt;sub&lt;1,2&gt;&gt;&gt;</code>...). This allows me to literally copy-paste the C implementation provided by the article:</p> <pre><code>template&lt;typename T , typename TERMS_COUNT = mpl::uinteger&lt;4&gt;&gt; struct sin_t; template&lt;typename T , typename TERMS_COUNT = mpl::uinteger&lt;4&gt;&gt; using sin = typename sin_t&lt;T,TERMS_COUNT&gt;::result; /* * sin() function implementation through Taylor series (Check http://www10.informatik.uni-erlangen.de/~pflaum/pflaum/ProSeminar/meta-art.html) * * The C equivalent code is: * * // Calculate sin(x) using j terms * float sine(float x, int j) * { * float val = 1; * * for (int k = j - 1; k &gt;= 0; --k) * val = 1 - x*x/(2*k+2)/(2*k+3)*val; * * return x * val; * } */ template&lt;mpl::fpbits BITS , mpl::fbcount PRECISION , unsigned int TERMS_COUNT&gt; struct sin_t&lt;mpl::fixed_point&lt;BITS,PRECISION&gt;,mpl::uinteger&lt;TERMS_COUNT&gt;&gt; { private: using x = mpl::fixed_point&lt;BITS,PRECISION&gt;; using begin = mpl::make_integer_backward_iterator&lt;TERMS_COUNT-1&gt;; using end = mpl::make_integer_backward_iterator&lt;-1&gt;; using one = mpl::decimal&lt;1,0,PRECISION&gt;; using two = mpl::decimal&lt;2,0,PRECISION&gt;; using three = mpl::decimal&lt;3,0,PRECISION&gt;; template&lt;typename K , typename VAL&gt; struct kernel : public mpl::function&lt;decltype( one() - ( x() * x() )/(two() * K() + two())/(two()*K()+three())*VAL() )&gt; {}; public: using result = decltype( x() * mpl::for_loop&lt;begin , end , one , kernel&gt;() ); }; </code></pre> <p><a href="https://github.com/Manu343726/Turbo/blob/ad6ca3188bd68f27db1b49417c4c03ff1dd2186e/trigonometry.hpp" rel="nofollow noreferrer">Here</a> is the header of the implementation in the project repo.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload