<?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[float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird]]></title><description><![CDATA[<p>Der Titel sagt schon alles.</p>
<pre><code class="language-cpp">float f = 3.6f;

cout &lt;&lt; f * 10.0f &lt;&lt; endl;

unsigned int uif = f * 10.0f;

cout &lt;&lt; uif &lt;&lt; endl;
</code></pre>
<p>Ausgabe:<br />
36<br />
35</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/252124/float-zu-int-gt-cout-gibt-etwas-anderes-aus-als-wenn-es-zuerst-einer-variable-zugewiesen-wird</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 02:20:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/252124.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Oct 2009 22:59:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Wed, 14 Oct 2009 22:59:45 GMT]]></title><description><![CDATA[<p>Der Titel sagt schon alles.</p>
<pre><code class="language-cpp">float f = 3.6f;

cout &lt;&lt; f * 10.0f &lt;&lt; endl;

unsigned int uif = f * 10.0f;

cout &lt;&lt; uif &lt;&lt; endl;
</code></pre>
<p>Ausgabe:<br />
36<br />
35</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792754</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792754</guid><dc:creator><![CDATA[WieJetzt]]></dc:creator><pubDate>Wed, 14 Oct 2009 22:59:45 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Wed, 14 Oct 2009 23:07:10 GMT]]></title><description><![CDATA[<p>Da kommt bedingt durch die Ungenauigkeit von Fließkommazahlen 35.9999... heraus, wird also zu 35 abgerundet.<br />
Wenn du vorher noch numeric_limits&lt;float&gt;::epsilon() addierst, sollte das richtige Ergebnis herauskommen.<br />
Und nimm am besten double, wenn es keinen guten Grund dagegen gibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792757</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792757</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Wed, 14 Oct 2009 23:07:10 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Wed, 14 Oct 2009 23:10:50 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">float f = 3.6f;

cout &lt;&lt; static_cast&lt;int&gt;(f * 10.0f) &lt;&lt; endl;

unsigned int uif = f * 10.0f;

cout &lt;&lt; uif &lt;&lt; endl;
</code></pre>
<p>Ausgabe:<br />
35<br />
35</p>
<p>Warum allerdings 35 und nicht 36, kann ich auf die Schnelle nicht sagen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792758</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792758</guid><dc:creator><![CDATA[ipsec]]></dc:creator><pubDate>Wed, 14 Oct 2009 23:10:50 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Wed, 14 Oct 2009 23:49:14 GMT]]></title><description><![CDATA[<p>Mit double funktionierts.</p>
<p>Ich möchte double nämlich als long speichern, da ich aus dem WinAPI die Interlocked-Funktionen für Kommazahlen verwenden möchte, die nehmen aber nur long an.<br />
Deshalb dachte ich mir (da ich eh nur kleinere Werte brauche, und nur mit einer Nachkommastelle), die Eingabe mit 10 zu multiplizieren und dann bei der Ausgabe wieder durch 10 zu teilen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792767</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792767</guid><dc:creator><![CDATA[WieJetzt]]></dc:creator><pubDate>Wed, 14 Oct 2009 23:49:14 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Thu, 15 Oct 2009 09:25:30 GMT]]></title><description><![CDATA[<p>Multiplizier lieber mit Potenzen von 2, das dürfte besser funktionieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792807</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792807</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 15 Oct 2009 09:25:30 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Thu, 15 Oct 2009 09:32:53 GMT]]></title><description><![CDATA[<p>Nanyuki schrieb:</p>
<blockquote>
<p>Wenn du vorher noch numeric_limits&lt;float&gt;::epsilon() addierst, sollte das richtige Ergebnis herauskommen.</p>
</blockquote>
<p>Kommt mir wie Voodoo vor. Epsilon ist viel zu klein, um in dem Wertebereich etwas zu bewirken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792816</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792816</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 15 Oct 2009 09:32:53 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Thu, 15 Oct 2009 12:12:13 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>Nanyuki schrieb:</p>
<blockquote>
<p>Wenn du vorher noch numeric_limits&lt;float&gt;::epsilon() addierst, sollte das richtige Ergebnis herauskommen.</p>
</blockquote>
<p>Kommt mir wie Voodoo vor. Epsilon ist viel zu klein, um in dem Wertebereich etwas zu bewirken.</p>
</blockquote>
<p>Könnte klappen.</p>
<pre><code class="language-cpp">float f = 3.6f; 
cout &lt;&lt; f * 10.0f &lt;&lt; endl; 
unsigned int uif = f * 10.0f; 
cout &lt;&lt; uif &lt;&lt; endl;
</code></pre>
<p>kann der kumpel innendrin ja gar nicht und denkt sich vielleicht</p>
<pre><code class="language-cpp">float f = 3.59999999999999532f;//nächstbeste darstellbare zahl um 3.6
cout &lt;&lt; f * 10.0f &lt;&lt; endl; 
unsigned int uif = f * 10.0f; 
cout &lt;&lt; uif &lt;&lt; endl;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1792864</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792864</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Thu, 15 Oct 2009 12:12:13 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Thu, 15 Oct 2009 12:24:55 GMT]]></title><description><![CDATA[<p>Schon klar, soweit die Idee ... aber Epsilon ist trotzdem zu klein dafür <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="🙂"
    /></p>
<p>Epsilon ist die kleinste Zahl, so dass 1+Epsilon &gt; 1 ist. Das heißt, 1 ist 1.0000*2^0 und 1+Epsilon ist 1.0001*2^0 (mal float der Anschaulichkeit halber mit 4 Binärstellen angenommen), Epsilon muss folglich 1*2^-4 sein. Jetzt nimmst du beispielsweise 2+Epsilon, also 1.0000*2^1 + 1*2^-4 und bekommst 1.0000(1)*2^1. Das in Klammern war das Epsilon ...</p>
<p>Wenn, dann sollte man 3.6*epsilon drauf addieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792871</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792871</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 15 Oct 2009 12:24:55 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Thu, 15 Oct 2009 12:29:16 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>Wenn, dann sollte man 3.6*epsilon drauf addieren.</p>
</blockquote>
<p>ne... (f+eps)*10.f...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792872</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792872</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 15 Oct 2009 12:29:16 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Thu, 15 Oct 2009 14:16:46 GMT]]></title><description><![CDATA[<p>Nomen est omen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792932</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792932</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 15 Oct 2009 14:16:46 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Thu, 15 Oct 2009 15:25:32 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>Nomen est omen</p>
</blockquote>
<p>um bei deinen 4 stellen zu bleiben:<br />
3.5999 * 10 = 35.9990<br />
wenn man jz 3.6*0.0001 draufaddiert, bekommt man eben nur 35.9993<br />
das ist genau so wenig 36 wie 35.9990...</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792966</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792966</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 15 Oct 2009 15:25:32 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Thu, 15 Oct 2009 15:53:02 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>Bashar schrieb:</p>
<blockquote>
<p>Nomen est omen</p>
</blockquote>
<p>um bei deinen 4 stellen zu bleiben:<br />
3.5999 * 10 = 35.9990</p>
</blockquote>
<p>Meine 4 Stellen sind binär. Im Dezimalsystem sind 3.6 und 1 in derselben Größenordnung, im Binärsystem nicht. Versuch dein Beispiel doch mal mit 13.599.</p>
<blockquote>
<p>wenn man jz 3.6*0.0001 draufaddiert, bekommt man eben nur 35.9993<br />
das ist genau so wenig 36 wie 35.9990...</p>
</blockquote>
<p>Das wird auch vorher drauf addiert, nicht erst danach. Also (f+f*eps)*10. Das ist auch im ganzen Thread bisher so gesagt wurden, wie kommst du darauf, dass von nachträglicher Addition die Rede ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792981</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792981</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 15 Oct 2009 15:53:02 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Thu, 15 Oct 2009 16:12:27 GMT]]></title><description><![CDATA[<p>oh - sry... war wohl beim lesen ein wenig abgelenkt &gt;&lt;</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1792991</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1792991</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 15 Oct 2009 16:12:27 GMT</pubDate></item><item><title><![CDATA[Reply to float zu int -&amp;gt; cout gibt etwas anderes aus als wenn es zuerst einer Variable zugewiesen wird on Thu, 15 Oct 2009 17:02:41 GMT]]></title><description><![CDATA[<p>Nanyuki schrieb:</p>
<blockquote>
<p>Und nimm am besten double, wenn es keinen guten Grund dagegen gibt.</p>
</blockquote>
<p>Das verschiebt doch das Problem nur.</p>
<p>Wenn man nachher eine ganze Zahl will, wie wärs mit Runden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793019</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793019</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Thu, 15 Oct 2009 17:02:41 GMT</pubDate></item></channel></rss>