<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Fixpoint Arithmetics]]></title><description><![CDATA[<p>I want to multiply the probabilities 0.9999* 0.9955* 0.6360... as fixpoint(unsigned short 16 bit, 14 bit fractional part) I think, I cut too much off. What part of in between value after multiplication should I take for further multiplication?</p>
<p>#include &lt;stdio.h&gt;<br />
//#include &lt;new&gt;</p>
<p>#include &lt;string.h&gt;<br />
#include &lt;stdlib.h&gt;</p>
<p>unsigned short zweihoch(short value) { //2^(12)<br />
unsigned short ans = 1;<br />
int i;</p>
<p>for (i = 0; i &lt; value; i++) {<br />
ans = 2 * ans;<br />
}</p>
<p>return ans;<br />
}</p>
<p>double zweihochneg(short value) { //2^(-12)<br />
double ans = 1;<br />
int i;</p>
<p>for (i = 0; i &lt; -value; i++) {<br />
ans = 2 * ans;<br />
}<br />
ans = 1 / ans;</p>
<p>return ans;<br />
}</p>
<p>unsigned short umul16hi(unsigned short a, unsigned short b) //multiplication 16*16 stored in 16, takes the right 16 bits, normal mult cuts 16 left bits out<br />
{<br />
unsigned short ans = 0;<br />
/* split operands into halves */<br />
unsigned short al1 = a &lt;&lt; 8;<br />
unsigned short al = al1 &gt;&gt; 8;<br />
unsigned short ah = a &gt;&gt; 8;</p>
<p>unsigned short bl1 = b &lt;&lt; 8;<br />
unsigned short bl = bl1 &gt;&gt; 8;<br />
unsigned short bh = b &gt;&gt; 8;<br />
/* compute partial products */<br />
unsigned short p0 = al * bl;<br />
unsigned short p1 = al * bh;<br />
unsigned short p11 = p1 &lt;&lt; 8;<br />
unsigned short p1_s = p11 &gt;&gt; 8;</p>
<p>unsigned short p2 = ah * bl;<br />
unsigned short p3 = ah * bh;<br />
unsigned short p21 = p2 &lt;&lt; 8;<br />
unsigned short p2_s = p21 &gt;&gt; 8;</p>
<p>/* sum partial products */<br />
unsigned short cy = ((p0 &gt;&gt; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--smiling_face_with_sunglasses"
      title="8)"
      alt="😎"
    /> + (unsigned short)p1_s + (unsigned short)p2_s) &gt;&gt; 8;<br />
return ans = (p3 + (p2 &gt;&gt; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--smiling_face_with_sunglasses"
      title="8)"
      alt="😎"
    /> + (p1 &gt;&gt; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--smiling_face_with_sunglasses"
      title="8)"
      alt="😎"
    /> + cy);<br />
}</p>
<p>int main()<br />
{<br />
unsigned short Prob_QAM = 0;<br />
double Prob_double[6] = { 0.9999, 0.9955, 0.6360, 0.7767, 0.6700, 0.6057 };<br />
unsigned short Prob[6] = Prob_double * zweihoch(12); // circa 4095 4077 2687 3181 2744 2480<br />
Prob_QAM = umul16hi( Prob[0] , Prob[1] );<br />
Prob_QAM = Prob_QAM * zweihoch(12); //cuts too much<br />
Prob_QAM = umul16hi( Prob_QAM , Prob[2]) * zweihoch(12); //cuts too much<br />
Prob_QAM = umul16hi( Prob_QAM , Prob[3]) * zweihoch(12); //cuts too much<br />
Prob_QAM = umul16hi( Prob_QAM , Prob[4]) * zweihoch(12); //cuts too much<br />
Prob_QAM = umul16hi( Prob_QAM , Prob[5]) * zweihoch(12); //cuts too much</p>
<p>Prob_QAM_double = 0.1995; //Prob_QAM must be like this<br />
return 0;<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/338727/fixpoint-arithmetics</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 07:01:14 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/338727.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 Jul 2016 14:09:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fixpoint Arithmetics on Tue, 05 Jul 2016 14:09:51 GMT]]></title><description><![CDATA[<p>I want to multiply the probabilities 0.9999* 0.9955* 0.6360... as fixpoint(unsigned short 16 bit, 14 bit fractional part) I think, I cut too much off. What part of in between value after multiplication should I take for further multiplication?</p>
<p>#include &lt;stdio.h&gt;<br />
//#include &lt;new&gt;</p>
<p>#include &lt;string.h&gt;<br />
#include &lt;stdlib.h&gt;</p>
<p>unsigned short zweihoch(short value) { //2^(12)<br />
unsigned short ans = 1;<br />
int i;</p>
<p>for (i = 0; i &lt; value; i++) {<br />
ans = 2 * ans;<br />
}</p>
<p>return ans;<br />
}</p>
<p>double zweihochneg(short value) { //2^(-12)<br />
double ans = 1;<br />
int i;</p>
<p>for (i = 0; i &lt; -value; i++) {<br />
ans = 2 * ans;<br />
}<br />
ans = 1 / ans;</p>
<p>return ans;<br />
}</p>
<p>unsigned short umul16hi(unsigned short a, unsigned short b) //multiplication 16*16 stored in 16, takes the right 16 bits, normal mult cuts 16 left bits out<br />
{<br />
unsigned short ans = 0;<br />
/* split operands into halves */<br />
unsigned short al1 = a &lt;&lt; 8;<br />
unsigned short al = al1 &gt;&gt; 8;<br />
unsigned short ah = a &gt;&gt; 8;</p>
<p>unsigned short bl1 = b &lt;&lt; 8;<br />
unsigned short bl = bl1 &gt;&gt; 8;<br />
unsigned short bh = b &gt;&gt; 8;<br />
/* compute partial products */<br />
unsigned short p0 = al * bl;<br />
unsigned short p1 = al * bh;<br />
unsigned short p11 = p1 &lt;&lt; 8;<br />
unsigned short p1_s = p11 &gt;&gt; 8;</p>
<p>unsigned short p2 = ah * bl;<br />
unsigned short p3 = ah * bh;<br />
unsigned short p21 = p2 &lt;&lt; 8;<br />
unsigned short p2_s = p21 &gt;&gt; 8;</p>
<p>/* sum partial products */<br />
unsigned short cy = ((p0 &gt;&gt; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--smiling_face_with_sunglasses"
      title="8)"
      alt="😎"
    /> + (unsigned short)p1_s + (unsigned short)p2_s) &gt;&gt; 8;<br />
return ans = (p3 + (p2 &gt;&gt; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--smiling_face_with_sunglasses"
      title="8)"
      alt="😎"
    /> + (p1 &gt;&gt; <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--smiling_face_with_sunglasses"
      title="8)"
      alt="😎"
    /> + cy);<br />
}</p>
<p>int main()<br />
{<br />
unsigned short Prob_QAM = 0;<br />
double Prob_double[6] = { 0.9999, 0.9955, 0.6360, 0.7767, 0.6700, 0.6057 };<br />
unsigned short Prob[6] = Prob_double * zweihoch(12); // circa 4095 4077 2687 3181 2744 2480<br />
Prob_QAM = umul16hi( Prob[0] , Prob[1] );<br />
Prob_QAM = Prob_QAM * zweihoch(12); //cuts too much<br />
Prob_QAM = umul16hi( Prob_QAM , Prob[2]) * zweihoch(12); //cuts too much<br />
Prob_QAM = umul16hi( Prob_QAM , Prob[3]) * zweihoch(12); //cuts too much<br />
Prob_QAM = umul16hi( Prob_QAM , Prob[4]) * zweihoch(12); //cuts too much<br />
Prob_QAM = umul16hi( Prob_QAM , Prob[5]) * zweihoch(12); //cuts too much</p>
<p>Prob_QAM_double = 0.1995; //Prob_QAM must be like this<br />
return 0;<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2501330</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501330</guid><dc:creator><![CDATA[bobotic]]></dc:creator><pubDate>Tue, 05 Jul 2016 14:09:51 GMT</pubDate></item><item><title><![CDATA[Reply to Fixpoint Arithmetics on Tue, 05 Jul 2016 16:21:46 GMT]]></title><description><![CDATA[<p>I can see, that u name your functions in german language. Also i have seen in your other postings, that u are able to express you in german.<br />
Are u too bescheuert, to recognize, that this is a german forum, or why do u quäl us with english written questions?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2501351</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501351</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Tue, 05 Jul 2016 16:21:46 GMT</pubDate></item><item><title><![CDATA[Reply to Fixpoint Arithmetics on Wed, 06 Jul 2016 05:54:02 GMT]]></title><description><![CDATA[<p>schau Dir mal das Ergebnis von</p>
<pre><code>zweihoch(12);
</code></pre>
<p>an.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2501380</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501380</guid><dc:creator><![CDATA[zweihoch12]]></dc:creator><pubDate>Wed, 06 Jul 2016 05:54:02 GMT</pubDate></item><item><title><![CDATA[Reply to Fixpoint Arithmetics on Wed, 06 Jul 2016 07:23:53 GMT]]></title><description><![CDATA[<p>Belli schrieb:</p>
<blockquote>
<p>Are u too bescheuert, to recognize, that this is a german forum, or why do u quäl us with english written questions?</p>
</blockquote>
<p>I guess that's a result of &quot;kopieren&amp;einfügen&quot;. Let's check google... oh yes, found it: the same question 17 hours ago on stackoverflow</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2501385</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501385</guid><dc:creator><![CDATA[daddy_felix]]></dc:creator><pubDate>Wed, 06 Jul 2016 07:23:53 GMT</pubDate></item><item><title><![CDATA[Reply to Fixpoint Arithmetics on Wed, 06 Jul 2016 07:51:40 GMT]]></title><description><![CDATA[<p>... und umul16h kann der Compiler besser, als Du das da hingeschrieben hast.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2501388</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2501388</guid><dc:creator><![CDATA[zweihoch12]]></dc:creator><pubDate>Wed, 06 Jul 2016 07:51:40 GMT</pubDate></item></channel></rss>