<?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[cos&#x2F;sin berechnungsgeschwindigkeit?]]></title><description><![CDATA[<p>hallo,<br />
also ich wollte mal kurz wissen welche der beiden varianten zur cos/sin berechnung schneller ist?</p>
<ol>
<li></li>
</ol>
<p>cos(α) und sin(α) mit<br />
α = 2*atan(f/g) für g≠0<br />
α = π für g=0</p>
<p>oder 2)<br />
cos(α) = (g<sup>2</sup> - f<sup>2</sup>)/(g<sup>2</sup> + f<sup>2</sup>)<br />
sin(α) = 2*f*g/(g<sup>2</sup> + f<sup>2</sup>)</p>
<p>wobei f und g float-werte sind nicht beide gleichzeitig 0 werden.<br />
der hintergrund ist das ich sehr viele cosinus und sinus werte ausrechnen muss und daher gerne die schnellere verwenden möchte.<br />
vielen dank schonmal im voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/214163/cos-sin-berechnungsgeschwindigkeit</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 18:40:40 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/214163.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 May 2008 13:14:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to cos&#x2F;sin berechnungsgeschwindigkeit? on Mon, 26 May 2008 13:14:58 GMT]]></title><description><![CDATA[<p>hallo,<br />
also ich wollte mal kurz wissen welche der beiden varianten zur cos/sin berechnung schneller ist?</p>
<ol>
<li></li>
</ol>
<p>cos(α) und sin(α) mit<br />
α = 2*atan(f/g) für g≠0<br />
α = π für g=0</p>
<p>oder 2)<br />
cos(α) = (g<sup>2</sup> - f<sup>2</sup>)/(g<sup>2</sup> + f<sup>2</sup>)<br />
sin(α) = 2*f*g/(g<sup>2</sup> + f<sup>2</sup>)</p>
<p>wobei f und g float-werte sind nicht beide gleichzeitig 0 werden.<br />
der hintergrund ist das ich sehr viele cosinus und sinus werte ausrechnen muss und daher gerne die schnellere verwenden möchte.<br />
vielen dank schonmal im voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516921</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516921</guid><dc:creator><![CDATA[StarCraftFeuerteufel]]></dc:creator><pubDate>Mon, 26 May 2008 13:14:58 GMT</pubDate></item><item><title><![CDATA[Reply to cos&#x2F;sin berechnungsgeschwindigkeit? on Mon, 26 May 2008 13:27:55 GMT]]></title><description><![CDATA[<p>schreib dir ein testprogramm und stopp die zeit, z.b. mit der funktion clock()<br />
mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516933</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516933</guid><dc:creator><![CDATA[gratistipp]]></dc:creator><pubDate>Mon, 26 May 2008 13:27:55 GMT</pubDate></item><item><title><![CDATA[Reply to cos&#x2F;sin berechnungsgeschwindigkeit? on Mon, 26 May 2008 13:28:11 GMT]]></title><description><![CDATA[<p>Ich denke, dass die zweite Variante um einiges schneller sein dürfte, da die mathematischen Funktionen wie atan sich erfahrungsgemäß relativ viel Zeit bei der Berechnung lassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516934</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516934</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Mon, 26 May 2008 13:28:11 GMT</pubDate></item><item><title><![CDATA[Reply to cos&#x2F;sin berechnungsgeschwindigkeit? on Mon, 26 May 2008 13:32:08 GMT]]></title><description><![CDATA[<p>Nanyuki schrieb:</p>
<blockquote>
<p>Ich denke, dass die zweite Variante um einiges schneller sein dürfte, da die mathematischen Funktionen wie atan sich erfahrungsgemäß relativ viel Zeit bei der Berechnung lassen.</p>
</blockquote>
<p>Erfahrungsgemäß?<br />
Meines Wissens sind die meisten dieser Funktionen über Wertetabellen implementiert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516937</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516937</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Mon, 26 May 2008 13:32:08 GMT</pubDate></item><item><title><![CDATA[Reply to cos&#x2F;sin berechnungsgeschwindigkeit? on Mon, 26 May 2008 13:33:46 GMT]]></title><description><![CDATA[<p>Du kannst auch eine eigene schnellere Funktion schreiben.<br />
Ich hab mal vor einer Weile das hier geschrieben:</p>
<pre><code class="language-cpp">float SinFast(const float f)
{
	float fTemp_3=f*f*f;
	return( f&gt;PI
			? SinFast(f-2.F*PI)
			: f&lt;-PI
			  ? SinFast(f+2.F*PI)
			  : (f - 0.0001984126984F * fTemp_3 * fTemp_3 * f           // f^7/7! +f (f^1/1!=f)
			       + 0.0083333333333F * fTemp_3 * f * f                 // f^5/5!
				   - 0.1666666666667F * fTemp_3  ));                    // f^3/3!
}
float CosFast(float f)
{	return( SinFast(f+.5F*PI) );}
</code></pre>
<p>ist schneller, aber ab manchmal etwas ungenau. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516938</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516938</guid><dc:creator><![CDATA[Blaze]]></dc:creator><pubDate>Mon, 26 May 2008 13:33:46 GMT</pubDate></item><item><title><![CDATA[Reply to cos&#x2F;sin berechnungsgeschwindigkeit? on Mon, 26 May 2008 13:38:23 GMT]]></title><description><![CDATA[<p>an die wertetabellen hatte ich auch schon gedacht, allerdings weiß ich halt nicht genau, ob das immer noch schneller ist als die paar operation auszuführen und genau das ist frage. da bei beiden eine division ausgeführt werden muss kann man diese operation bei der betrachtugn weglassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516943</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516943</guid><dc:creator><![CDATA[StarCraftFeuerteufel]]></dc:creator><pubDate>Mon, 26 May 2008 13:38:23 GMT</pubDate></item><item><title><![CDATA[Reply to cos&#x2F;sin berechnungsgeschwindigkeit? on Mon, 26 May 2008 13:38:38 GMT]]></title><description><![CDATA[<p>.filmor schrieb:</p>
<blockquote>
<p>Erfahrungsgemäß?<br />
Meines Wissens sind die meisten dieser Funktionen über Wertetabellen implementiert...</p>
</blockquote>
<p>Die Implementierungsdetails kenne ich nicht... aber im Vergleich zu Divisionen und erst recht zu Multiplikationen haben diese Funktionen eine weitaus höhere Laufzeit. Deswegen vermute ich, dass die zweite Variante schneller sein dürfte (wenn beide wirklich gleichwertig sind).<br />
Aber naja, im Zweifelsfall einfach nachmessen... das ist wohl der bessere Weg, anstatt sich auf irgendwelche Ratschläge zu verlassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516944</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Mon, 26 May 2008 13:38:38 GMT</pubDate></item><item><title><![CDATA[Reply to cos&#x2F;sin berechnungsgeschwindigkeit? on Mon, 26 May 2008 13:39:15 GMT]]></title><description><![CDATA[<p>noch mehr ungenauigkeit, als numerisch sowieso schon gegeben ist, kann ich mir leider nicht leisten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516946</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516946</guid><dc:creator><![CDATA[StarCraftFeuerteufel]]></dc:creator><pubDate>Mon, 26 May 2008 13:39:15 GMT</pubDate></item><item><title><![CDATA[Reply to cos&#x2F;sin berechnungsgeschwindigkeit? on Mon, 26 May 2008 14:12:14 GMT]]></title><description><![CDATA[<p>Edit: war wohl (teilweise) Unsinn.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516962</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Mon, 26 May 2008 14:12:14 GMT</pubDate></item><item><title><![CDATA[Reply to cos&#x2F;sin berechnungsgeschwindigkeit? on Mon, 26 May 2008 14:31:58 GMT]]></title><description><![CDATA[<p>also ich hab mir mal kurz folgenden code geschrieben. für die klasse cclock mag jeder seine eigene zeitmessung einfügen.</p>
<pre><code class="language-cpp">cclock clk;
	const float d = 1000.0f;
	const float step = 0.5f;
	float f;
	float g;
	float ff;
	float gg;
	float abs;
	float a;
	float c;
	float s;
	int i = 5;
	while(i--)
	{
		clk.set_start_time();
		for(f = -d; f &lt;= d; f += step)
			for(g = -d; g &lt;= d; g += step)
				if(f != 0 || g != 0)
				{
					ff = f*f;
					gg = g*g;
					abs = 1 / (ff + gg);
					c = (gg - ff) * abs;
					s = 2.0f * f * g * abs;
				};
		clk.set_finish_time();
		std::cout &lt;&lt; &quot;Zeitmessung ohne Cos(), Sin()&quot; &lt;&lt; clk &lt;&lt; std::endl;

		clk.set_start_time();
		for(f = -d; f &lt;= d; f += step)
			for(g = -d; g &lt;= d; g += step)
			{
				if(g == 0)
				{
					c = -1;
					s = 0;
				}
				else
				{
					a = 2 * atan(f/g);
					c = cos(a);
					s = sin(a);
				};
			};
		clk.set_finish_time();
		std::cout &lt;&lt; &quot;Zeitmessung mit Cos(), Sin()&quot; &lt;&lt; clk &lt;&lt; std::endl;
	}
</code></pre>
<pre><code>Zeitmessung ohne Cos(), Sin()t = 0.359s
Zeitmessung mit Cos(), Sin()t = 9.297s
Zeitmessung ohne Cos(), Sin()t = 0.36s
Zeitmessung mit Cos(), Sin()t = 9.36s
Zeitmessung ohne Cos(), Sin()t = 0.375s
Zeitmessung mit Cos(), Sin()t = 9.282s
Zeitmessung ohne Cos(), Sin()t = 0.328s
Zeitmessung mit Cos(), Sin()t = 9.36s
Zeitmessung ohne Cos(), Sin()t = 0.36s
Zeitmessung mit Cos(), Sin()t = 9.328s
</code></pre>
<p>resultat ist das cos(),sin(),atan() berechnung ca. um den faktor 30 langsamer war als die andere methode, damit dürfte der gewinner feststehen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1516970</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1516970</guid><dc:creator><![CDATA[StarCraftFeuerteufel]]></dc:creator><pubDate>Mon, 26 May 2008 14:31:58 GMT</pubDate></item><item><title><![CDATA[Reply to cos&#x2F;sin berechnungsgeschwindigkeit? on Mon, 26 May 2008 15:29:36 GMT]]></title><description><![CDATA[<p>Ich habe auch mal eine Sinusfunktion selbst geschrieben. ( Ich lerne noch ).</p>
<pre><code>double sinius(double x)
{
double Sinus;             
double xquadrat, x_hoch_3, x_hoch_5, x_hoch_7, x_hoch_9, x_hoch_11, x_hoch_13;
//double x_hoch_15;
double PI = 3.141592653589793;
double ZweiPI = 6.283185307179586;
double PIhalbe = 1.570796326794897;

	while (x &lt; 0) x = x + ZweiPI;    //Jetzt ist x auf jeden Fall &gt; 0
	while (x &gt; ZweiPI) x = x - ZweiPI; //Jetzt liegt x im Intervall [0..ZweiPI]
	if (x &gt; PI) x = x - ZweiPI;       //Jetzt liegt x im Intervall [-PI..PI]
	if (x &gt; PIhalbe) x = PI - x;    //Jetzt liegt x im Intervall [-PI..PIhalbe]
	if (x &lt; -PIhalbe) x = -x - PI; //Jetzt liegt x im Intervall [-PIhalbe..PIhalbe]

	xquadrat = x * x;                 
	x_hoch_3 = x * xquadrat;          
	x_hoch_5 = x_hoch_3 * xquadrat;   
	x_hoch_7 = x_hoch_5 * xquadrat; 
	x_hoch_9 = x_hoch_7 * xquadrat;   
	x_hoch_11 = x_hoch_9 * xquadrat;   
	x_hoch_13 = x_hoch_11 * xquadrat;  
//	x_hoch_15 = x_hoch_13 * xquadrat;  

	return x - x_hoch_3/6 + x_hoch_5/120 - x_hoch_7/5040 + x_hoch_9/362880
	        - x_hoch_11/39916800 + x_hoch_13/6227020800.0 
	       /* - x_hoch_15/1307674368000.0 */  ;
</code></pre>
<p>Ich hoffe, es rechnet richtig.</p>
<p>Etwa 100000 Berechnungen werden durchgeführt, noch bevor man mit den Wimpern zucken kann. Erst ab einer Million Berechnungen muß man einen kleinen Augenblick warten. Die normale Sinusfunktin sin() aus &lt;math.h&gt; ist allerdings noch einmal etwa doppelt so schnell. Es müssen wohl sehr viele Berechnungen sein, die FreakyBKA da durchführen will.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1517027</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1517027</guid><dc:creator><![CDATA[Sinius]]></dc:creator><pubDate>Mon, 26 May 2008 15:29:36 GMT</pubDate></item></channel></rss>