<?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[sin()&#x2F;cos() liefern falsche Werte]]></title><description><![CDATA[<p>Hi<br />
Ich habe seit kurzem das Problem, dass cos()/sin() bei bestimmten Werten falsche Ergebnisse liefern.<br />
Hier mal ein paar Beispiele:</p>
<pre><code class="language-cpp">int main()
{
	std::wcout &lt;&lt; sin(181*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; // -0.0174526
	std::wcout &lt;&lt; sin(D3DX_PI) &lt;&lt; L&quot;\n&quot;;		 // -8.74228e-008
	std::wcout &lt;&lt; sin(179*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; //  0.0174525
	std::wcout &lt;&lt; sin(90*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;;  //  1    
	std::wcout &lt;&lt; cos(180*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; // -1 
	std::wcout &lt;&lt; cos(0.0f) &lt;&lt; L&quot;\n&quot;;			//  1 
	std::wcout &lt;&lt; cos(270*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; //  1.19249e-008
	std::wcout &lt;&lt; cos(90*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;;  // -4.37114e-008 
	std::wcout &lt;&lt; cos(91*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;;  // -0.0174525
}
</code></pre>
<p>Wie kommen bei einigen diese komischen Werte zustande? Kann man das irgendwie beheben?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/160057/sin-cos-liefern-falsche-werte</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 03:46:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/160057.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 21 Sep 2006 14:09:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to sin()&#x2F;cos() liefern falsche Werte on Thu, 21 Sep 2006 14:09:04 GMT]]></title><description><![CDATA[<p>Hi<br />
Ich habe seit kurzem das Problem, dass cos()/sin() bei bestimmten Werten falsche Ergebnisse liefern.<br />
Hier mal ein paar Beispiele:</p>
<pre><code class="language-cpp">int main()
{
	std::wcout &lt;&lt; sin(181*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; // -0.0174526
	std::wcout &lt;&lt; sin(D3DX_PI) &lt;&lt; L&quot;\n&quot;;		 // -8.74228e-008
	std::wcout &lt;&lt; sin(179*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; //  0.0174525
	std::wcout &lt;&lt; sin(90*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;;  //  1    
	std::wcout &lt;&lt; cos(180*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; // -1 
	std::wcout &lt;&lt; cos(0.0f) &lt;&lt; L&quot;\n&quot;;			//  1 
	std::wcout &lt;&lt; cos(270*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; //  1.19249e-008
	std::wcout &lt;&lt; cos(90*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;;  // -4.37114e-008 
	std::wcout &lt;&lt; cos(91*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;;  // -0.0174525
}
</code></pre>
<p>Wie kommen bei einigen diese komischen Werte zustande? Kann man das irgendwie beheben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141892</guid><dc:creator><![CDATA[noname#4124]]></dc:creator><pubDate>Thu, 21 Sep 2006 14:09:04 GMT</pubDate></item><item><title><![CDATA[Reply to sin()&#x2F;cos() liefern falsche Werte on Thu, 21 Sep 2006 14:13:35 GMT]]></title><description><![CDATA[<p>Die Funktionen erwarten ihre Parameter im Bogenmaß und geben ihre Ergebnisse auch wieder im Bogenmaß zurück.<br />
Edit: Guck mal hier -&gt; <a href="http://www.willemer.de/informatik/cpp/mathlib.htm" rel="nofollow">klick mich</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141896</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141896</guid><dc:creator><![CDATA[Vellas]]></dc:creator><pubDate>Thu, 21 Sep 2006 14:13:35 GMT</pubDate></item><item><title><![CDATA[Reply to sin()&#x2F;cos() liefern falsche Werte on Thu, 21 Sep 2006 14:25:21 GMT]]></title><description><![CDATA[<p>Vellas schrieb:</p>
<blockquote>
<p>Die Funktionen erwarten ihre Parameter im Bogenmaß und geben ihre Ergebnisse auch wieder im Bogenmaß zurück.<br />
Edit: Guck mal hier -&gt; <a href="http://www.willemer.de/informatik/cpp/mathlib.htm" rel="nofollow">klick mich</a></p>
</blockquote>
<p>Ich weiß, dass sie bogenmaß haben will, ich füttere sie ja auch mit Bogenmaß. Ich werde es demnächst anders berechnen, nämlich so wie bei deinem link, aber bei std::wcout &lt;&lt; sin(D3DX_PI) &lt;&lt; L&quot;\n&quot;; dürfte doch wohl gar nix schief laufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141912</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141912</guid><dc:creator><![CDATA[nonename##4124]]></dc:creator><pubDate>Thu, 21 Sep 2006 14:25:21 GMT</pubDate></item><item><title><![CDATA[Reply to sin()&#x2F;cos() liefern falsche Werte on Thu, 21 Sep 2006 14:43:15 GMT]]></title><description><![CDATA[<p>noname#4124 schrieb:</p>
<blockquote>
<p>Hi<br />
Ich habe seit kurzem das Problem, dass cos()/sin() bei bestimmten Werten falsche Ergebnisse liefern.<br />
Hier mal ein paar Beispiele:</p>
<pre><code class="language-cpp">int main()
{
	std::wcout &lt;&lt; sin(181*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; // -0.0174526
	std::wcout &lt;&lt; sin(D3DX_PI) &lt;&lt; L&quot;\n&quot;;		 // -8.74228e-008
	std::wcout &lt;&lt; sin(179*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; //  0.0174525
	std::wcout &lt;&lt; sin(90*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;;  //  1    
	std::wcout &lt;&lt; cos(180*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; // -1 
	std::wcout &lt;&lt; cos(0.0f) &lt;&lt; L&quot;\n&quot;;			//  1 
	std::wcout &lt;&lt; cos(270*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;; //  1.19249e-008
	std::wcout &lt;&lt; cos(90*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;;  // -4.37114e-008 
	std::wcout &lt;&lt; cos(91*D3DX_PI/180) &lt;&lt; L&quot;\n&quot;;  // -0.0174525
}
</code></pre>
<p>Wie kommen bei einigen diese komischen Werte zustande? Kann man das irgendwie beheben?</p>
</blockquote>
<p>ich nehme an, du beziehst dich auf die werte, die sehr nahe bei 0 liegen. das ist aber zu erwarten: auch D3DX_PI kann ja nur eine näherung an π sein - folglich wird auch der funktionswert ebenfalls etwas von 0 abweichen. ein double hat üblicherweise 53 signifikante bits, das sind etwa 5,7 dezimalstellen. das kann bei den trigonometrischen funktionen dann auch als abschätzung der genauigkeit des ergebnisses benutzt werden. die erhaltenen werten an den erwähnten stellen sind alle weitaus kleiner, würde man diese auf 5 oder 6 stellen nach dem komma runden, erhielte man die erwartete 0</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141929</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141929</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 21 Sep 2006 14:43:15 GMT</pubDate></item><item><title><![CDATA[Reply to sin()&#x2F;cos() liefern falsche Werte on Thu, 21 Sep 2006 14:51:23 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>ich nehme an, du beziehst dich auf die werte, die sehr nahe bei 0 liegen. das ist aber zu erwarten: auch D3DX_PI kann ja nur eine näherung an π sein - folglich wird auch der funktionswert ebenfalls etwas von 0 abweichen. ein double hat üblicherweise 53 signifikante bits, das sind etwa 5,7 dezimalstellen. das kann bei den trigonometrischen funktionen dann auch als abschätzung der genauigkeit des ergebnisses benutzt werden. die erhaltenen werten an den erwähnten stellen sind alle weitaus kleiner, würde man diese auf 5 oder 6 stellen nach dem komma runden, erhielte man die erwartete 0</p>
</blockquote>
<p>D.h. -4.37114e-008 ist gar nicht so weit weg von der 0 wie es aussieht? Sorry, aber ich kan mit dem e-008 überhaupt nichts anfangen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141938</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141938</guid><dc:creator><![CDATA[noname#4124]]></dc:creator><pubDate>Thu, 21 Sep 2006 14:51:23 GMT</pubDate></item><item><title><![CDATA[Reply to sin()&#x2F;cos() liefern falsche Werte on Thu, 21 Sep 2006 14:57:19 GMT]]></title><description><![CDATA[<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mo>−</mo><mn>4</mn><mi mathvariant="normal">.</mi><mn>3</mn><mn>7</mn><mn>1</mn><mn>1</mn><mn>4</mn><mi>e</mi><mo>−</mo><mn>0</mn><mn>0</mn><mn>8</mn><mo>=</mo><mo>−</mo><mn>4</mn><mi mathvariant="normal">.</mi><mn>3</mn><mn>7</mn><mn>1</mn><mn>1</mn><mn>4</mn><mo>∗</mo><mn>1</mn><msup><mn>0</mn><mrow><mo>−</mo><mn>8</mn></mrow></msup><mo>=</mo><mo>−</mo><mn>0</mn><mi mathvariant="normal">.</mi><mn>0</mn><mn>0</mn><mn>0</mn><mn>0</mn><mn>0</mn><mn>0</mn><mn>0</mn><mn>4</mn><mn>3</mn><mn>7</mn><mn>1</mn><mn>1</mn><mn>4</mn></mrow><annotation encoding="application/x-tex">-4.37114e-008 = -4.37114*10^{-8} = -0.0000000437114</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.8141079999999999em;"></span><span class="strut bottom" style="height:0.897438em;vertical-align:-0.08333em;"></span><span class="base textstyle uncramped"><span class="mord">−</span><span class="mord mathrm">4</span><span class="mord mathrm">.</span><span class="mord mathrm">3</span><span class="mord mathrm">7</span><span class="mord mathrm">1</span><span class="mord mathrm">1</span><span class="mord mathrm">4</span><span class="mord mathit">e</span><span class="mbin">−</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span><span class="mord mathrm">8</span><span class="mrel">=</span><span class="mord">−</span><span class="mord mathrm">4</span><span class="mord mathrm">.</span><span class="mord mathrm">3</span><span class="mord mathrm">7</span><span class="mord mathrm">1</span><span class="mord mathrm">1</span><span class="mord mathrm">4</span><span class="mbin">∗</span><span class="mord mathrm">1</span><span class="mord"><span class="mord mathrm">0</span><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord scriptstyle uncramped"><span class="mord">−</span><span class="mord mathrm">8</span></span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span><span class="mrel">=</span><span class="mord">−</span><span class="mord mathrm">0</span><span class="mord mathrm">.</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span><span class="mord mathrm">4</span><span class="mord mathrm">3</span><span class="mord mathrm">7</span><span class="mord mathrm">1</span><span class="mord mathrm">1</span><span class="mord mathrm">4</span></span></span></span></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141944</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141944</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 21 Sep 2006 14:57:19 GMT</pubDate></item><item><title><![CDATA[Reply to sin()&#x2F;cos() liefern falsche Werte on Thu, 21 Sep 2006 15:00:54 GMT]]></title><description><![CDATA[<p>Ok. Alle unklarheiten beseitigt. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
Thx!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1141950</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1141950</guid><dc:creator><![CDATA[noname#4124]]></dc:creator><pubDate>Thu, 21 Sep 2006 15:00:54 GMT</pubDate></item></channel></rss>