<?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[Double Problem im Bezug auf Stellenprüfung]]></title><description><![CDATA[<p>Hallo an alle,</p>
<p>ich habe ein kleines Problem. Und zwar habe ich eine Funktion die ein bestimmtes Array oder einen Vector (ist egal) auf spezielle Werte prüft. Das funktioniert bei Integern auch wuderbar, das Problem ist aber, der Double.</p>
<p>Egal ob man 3.49 oder extra 3.49000000000000000 schreibt, es wird immer 3.499999999999999999999 daraus ... jedenfalls meistens, was auch wieder irritierend ist.</p>
<p>Hat jemand eine Idee woran das liegt?</p>
<pre><code class="language-cpp">int main( int argc, char* argv[] )
{
	int i_Val[] = { 7, 88, 36, 12 };
	vector&lt;double&gt; dbl_Vec;

	dbl_Vec.push_back(4.3);
	dbl_Vec.push_back(17.4);
	dbl_Vec.push_back(1.3);
	dbl_Vec.push_back(34.7);

	for( int i = 0; i &lt; 100; i++ )
		if( asm_search&lt;int&gt;(&amp;i_Val[0], &amp;i_Val[(int)sizeof(i_Val)/sizeof(int)], i) )
			cout &lt;&lt; i &lt;&lt; &quot;\tfound in vector list&quot; &lt;&lt; endl;

	cout &lt;&lt; nl &lt;&lt; endl;

	for( double d = 0.00000000000000000; d &lt; 40.00000000000000000; (d += 0.10000000000000000) )
	{
		if( FindValue&lt;double&gt;(&amp;dbl_Vec[0], &amp;dbl_Vec[dbl_Vec.size()-1], d) ) 
			cout &lt;&lt; d &lt;&lt; &quot;\tfound in array&quot; &lt;&lt; endl;
	}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/241113/double-problem-im-bezug-auf-stellenprüfung</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 17:44:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/241113.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 15 May 2009 20:13:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Double Problem im Bezug auf Stellenprüfung on Fri, 15 May 2009 20:13:27 GMT]]></title><description><![CDATA[<p>Hallo an alle,</p>
<p>ich habe ein kleines Problem. Und zwar habe ich eine Funktion die ein bestimmtes Array oder einen Vector (ist egal) auf spezielle Werte prüft. Das funktioniert bei Integern auch wuderbar, das Problem ist aber, der Double.</p>
<p>Egal ob man 3.49 oder extra 3.49000000000000000 schreibt, es wird immer 3.499999999999999999999 daraus ... jedenfalls meistens, was auch wieder irritierend ist.</p>
<p>Hat jemand eine Idee woran das liegt?</p>
<pre><code class="language-cpp">int main( int argc, char* argv[] )
{
	int i_Val[] = { 7, 88, 36, 12 };
	vector&lt;double&gt; dbl_Vec;

	dbl_Vec.push_back(4.3);
	dbl_Vec.push_back(17.4);
	dbl_Vec.push_back(1.3);
	dbl_Vec.push_back(34.7);

	for( int i = 0; i &lt; 100; i++ )
		if( asm_search&lt;int&gt;(&amp;i_Val[0], &amp;i_Val[(int)sizeof(i_Val)/sizeof(int)], i) )
			cout &lt;&lt; i &lt;&lt; &quot;\tfound in vector list&quot; &lt;&lt; endl;

	cout &lt;&lt; nl &lt;&lt; endl;

	for( double d = 0.00000000000000000; d &lt; 40.00000000000000000; (d += 0.10000000000000000) )
	{
		if( FindValue&lt;double&gt;(&amp;dbl_Vec[0], &amp;dbl_Vec[dbl_Vec.size()-1], d) ) 
			cout &lt;&lt; d &lt;&lt; &quot;\tfound in array&quot; &lt;&lt; endl;
	}

	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1711240</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1711240</guid><dc:creator><![CDATA[FrEEzE2046]]></dc:creator><pubDate>Fri, 15 May 2009 20:13:27 GMT</pubDate></item><item><title><![CDATA[Reply to Double Problem im Bezug auf Stellenprüfung on Fri, 15 May 2009 20:31:34 GMT]]></title><description><![CDATA[<p>Fließkommazahlen werden (idR) nicht als Dezimalzahlen gespeichert, sondern mit einer binären Basis. Daher ist die Darstellung als Dezimalzahl nicht immer optimal und du hast oft Rundungsfehler. Daher verwendet man == eigentlich nicht mit Fließkommazahlen. Und deine Schleife ist auch nicht gerade optimal.</p>
<p>Siehe hier, wie man es besser macht:<br />
<a href="http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm" rel="nofollow">http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm</a><br />
<a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.22.6768" rel="nofollow">http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.22.6768</a></p>
<p>Außerdem benutzt du doch offensichtlich C++ und nicht C! (btw. warum nimmst du ein eigenes FindValue und nicht std::find?)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1711250</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1711250</guid><dc:creator><![CDATA[rüdiger]]></dc:creator><pubDate>Fri, 15 May 2009 20:31:34 GMT</pubDate></item><item><title><![CDATA[Reply to Double Problem im Bezug auf Stellenprüfung on Fri, 15 May 2009 20:31:51 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-1819.html" rel="nofollow">rüdiger</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-10.html" rel="nofollow">ANSI C</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1711251</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1711251</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Fri, 15 May 2009 20:31:51 GMT</pubDate></item></channel></rss>