<?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[Performance von Test gegen Null mit kleinem Epsilon für floats]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgende Funktion IsZero() wird wird in meinem Code oft (!) aufgerufen und verursacht laut Profiler 19% meiner Rechenzeit. Meine einfache Frage daher: geht das schneller?</p>
<pre><code class="language-cpp">class CUtils
{
public:
    static const float ZERO;
    inline static bool IsZero(float f) 
    {
        return fabs(f) &lt;= ZERO; 
    };
}

// Util.cpp
const float CUtils::ZERO = 1e-5f;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/156362/performance-von-test-gegen-null-mit-kleinem-epsilon-für-floats</link><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 02:33:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/156362.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 16 Aug 2006 08:14:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 08:14:37 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgende Funktion IsZero() wird wird in meinem Code oft (!) aufgerufen und verursacht laut Profiler 19% meiner Rechenzeit. Meine einfache Frage daher: geht das schneller?</p>
<pre><code class="language-cpp">class CUtils
{
public:
    static const float ZERO;
    inline static bool IsZero(float f) 
    {
        return fabs(f) &lt;= ZERO; 
    };
}

// Util.cpp
const float CUtils::ZERO = 1e-5f;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1118046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118046</guid><dc:creator><![CDATA[FelixManke]]></dc:creator><pubDate>Wed, 16 Aug 2006 08:14:37 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 08:18:29 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">class CUtils
{
public:
    static const float ZERO;
    inline static bool IsZero(float&amp; f) 
    {
        return fabs(f) &lt;= ZERO; 
    };
}

// Util.cpp
const float CUtils::ZERO = 1e-5f;
</code></pre>
<p>Evtl. machts die Referenz was schneller. Oder du schaust dir genauer an was fabs macht.<br />
Und ob du das optimieren kannst...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118050</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118050</guid><dc:creator><![CDATA[phlox81]]></dc:creator><pubDate>Wed, 16 Aug 2006 08:18:29 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 08:27:20 GMT]]></title><description><![CDATA[<p>Ob das schneller ist als fabs?</p>
<pre><code class="language-cpp">return (f &gt; -ZERO) &amp;&amp; (f &lt; ZERO);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1118058</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118058</guid><dc:creator><![CDATA[FelixManke]]></dc:creator><pubDate>Wed, 16 Aug 2006 08:27:20 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 08:35:10 GMT]]></title><description><![CDATA[<p>FelixManke schrieb:</p>
<blockquote>
<p>Ob das schneller ist als fabs?</p>
<pre><code class="language-cpp">return (f &gt; -ZERO) &amp;&amp; (f &lt; ZERO);
</code></pre>
</blockquote>
<p>musst du wohl selbst testen/profilen. Evtl. koenntest du auch ueberlegen, welcher der beiden Terme oefter false zurueckgibt und den voran stellen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118063</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118063</guid><dc:creator><![CDATA[Blue-Tiger]]></dc:creator><pubDate>Wed, 16 Aug 2006 08:35:10 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 09:30:32 GMT]]></title><description><![CDATA[<p>die referenz duerfte nichts bringen.<br />
ob fabs schneller ist als ein zweiter compare, kommt drauf an, ob fabs als intrinsic ausgefuehrt wird - falls nicht passieren dabei gruselige dinge.<br />
der compiler sollte ungefaehr sowas produzieren:</p>
<pre><code>inline static bool IsZero(float f)
{
	bool result;
	_asm {
		xor     bl,bl
		fld     f
		fabs
		fcomp   ZERO
		fstsw   ax
		fwait     
		sahf      
		adc     bl,0
		mov     result,bl
	};
	return result;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1118118</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118118</guid><dc:creator><![CDATA[hellihjb]]></dc:creator><pubDate>Wed, 16 Aug 2006 09:30:32 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 09:41:30 GMT]]></title><description><![CDATA[<p>Hilfe :-)!</p>
<p>Aber huch! Wo ist denn mein letztes Posting hin? Naja, ich habe das mal geprofiled mit folgendem kleinen Test:</p>
<pre><code class="language-cpp">bool IsZero1(float f) 
{
    return fabs(f) &lt;= CUtils::ZERO; 
};
bool IsZero2(float f) 
{
    return (f &gt;= -CUtils::ZERO) &amp;&amp; (f &lt;= CUtils::ZERO); 
};

void Test()
{
    for(uint32 i = 0; i &lt; 10000000; i++)
    {
        float f = CUtils::Rand() - 0.5f;  // Rand() liefert float in [0,1]
        bool b1 = IsZero1(f);
        bool b2 = IsZero2(f);
    }
}
</code></pre>
<p>Dabei ist herausgekommen, dass IsZero2() nur ca. 40% der Zeit benötigt. Daher habe ich das dahingehend geändert.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/12877">@hellihjb</a><br />
Ich muss gestehen, dass ich Assembler nicht wirklich lesen kann, da ich nur die Grundlegenden Befehle kenne. Ist das ne Implementierung, die du mir vorschlägst? Funktioniert die auf verschiedenen Palttformen (Win / Linux)? Und was macht dabei z.B. xor bl,bl? Wo kommt 'bl' her?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118125</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118125</guid><dc:creator><![CDATA[FelixManke]]></dc:creator><pubDate>Wed, 16 Aug 2006 09:41:30 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:02:43 GMT]]></title><description><![CDATA[<p>Assembler hat mit dem Betriebssystem nichts zu tun sondern mit der CPU. So lange du eine x86 (kompatible) CPU verwendest wirst du keine Probleme haben. Du verwendest wohl den GCC (wegen der Linux/Windows Frage), dort wird nicht die Intel-Syntax verwendet sondern die AT&amp;T Syntax, da schreibt man von dir Register ein % vor die Register und der Quelloperand kommt vor dem Zieloperand.<br />
Inline-ASM im GCC sieht auch etwas anders aus.</p>
<p>bl ist das low Register von BX (=16Bit Register =&gt; bl die unteren 8Bit).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118152</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118152</guid><dc:creator><![CDATA[Lolz]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:02:43 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:07:40 GMT]]></title><description><![CDATA[<p>Ich entwickel für Windows (mit Visual Studio .NET) und für Linux (keine Ahnung, welcher Compiler, hab meinen Code bisher noch nicht auf Linux compilieren lassen). x86 Maschinen werden das schon alles sein...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118159</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118159</guid><dc:creator><![CDATA[FelixManke]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:07:40 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:14:09 GMT]]></title><description><![CDATA[<p>Erklärung zum asm-code:</p>
<pre><code class="language-asm">xor     bl,bl ; löscht das bl register ( =&gt; bl ist 0)
        fld     f ; schiebt dein float in die fpu (dort gibts nen stack wo die gespeichert werden)
        fabs  ;fabs halt, denke das ist klar
        fcomp   ZERO ; sollte auch klar sein (vergleich)
        fstsw   ax ; kopiert das fpu status registers nach ax
        fwait ; wartet, da fpu und cpu synchronisieren müssen zum datenaustausch
        sahf  ; kopiert das ah register in die cpu flags (jetzt haben wir das fpu ergebnis in der cpu)   
        adc     bl,0 ; add with carry addiert das carry flag darauf wenn es gesetzt ist, da zusätzlich 0 addiert wird hast du 0+1+0=1 wenn das carryflag gesetzt ist (=&gt; das ergebnis ist null) und 0+0+0=0 wenn das carryflag nicht gesetzt ist (=&gt; das ergebnis ist ungleich null)
        mov     result,bl ;speicher das ergebnis in result (eigentlich quatsch, klüger wäre ein mov eax,ebx)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1118166</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118166</guid><dc:creator><![CDATA[Netter Mensch]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:14:09 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:18:23 GMT]]></title><description><![CDATA[<p>Wow. Danke netter Mensch <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1118171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118171</guid><dc:creator><![CDATA[FelixManke]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:18:23 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:48:48 GMT]]></title><description><![CDATA[<blockquote>
<p>Ist das ne Implementierung, die du mir vorschlägst?<br />
Funktioniert die auf verschiedenen Palttformen (Win / Linux)?</p>
</blockquote>
<p>du koenntest den code zb zum vergleichen beim profilen einsetzen um herauszufinden, ob dein compiler sinnvollen code erzeugt.<br />
oder einfach mal mit dem debugger durch das disassembly-steppen und anzahl der instruktionen zaehlen.<br />
bzgl des codes muss man vielleicht noch kommentieren, dass die position des fpu-compare-flag im ah-register mit der position des carry-flags uebereinstimmt und man deswegen das resultat des vergleichs durch einfaches addieren des carry-flags erhaelt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118177</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118177</guid><dc:creator><![CDATA[hellihjb]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:48:48 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:29:46 GMT]]></title><description><![CDATA[<p>Mal ein bisschen OT die Frage: Womit profilest du deinen Code? Ich würde sowas auch gern mal mit meinen Code machen, aber das ist das erste mal das ich sowas hier im Forum lese.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118180</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118180</guid><dc:creator><![CDATA[flammenvogel]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:29:46 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:33:50 GMT]]></title><description><![CDATA[<p>zb <a href="http://www.devx.com/amd/Article/17305" rel="nofollow">AMD Code Analyst</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118185</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118185</guid><dc:creator><![CDATA[hellihjb]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:33:50 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:35:36 GMT]]></title><description><![CDATA[<p>Such einfach im Internet nach Profiler C++ oder so. Hier ist der Link zum Wikipediaartikel:<br />
<a href="http://de.wikipedia.org/wiki/Profiler_%28Programmierung%29" rel="nofollow">http://de.wikipedia.org/wiki/Profiler_(Programmierung)</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118189</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118189</guid><dc:creator><![CDATA[Vellas]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:35:36 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:37:33 GMT]]></title><description><![CDATA[<p>Und was mache ich wenn ich ein CPU von Intel habe. Kann ich dann auch dieses Programm benutzen oder brauche ich eins für Intel Prozessoren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118191</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118191</guid><dc:creator><![CDATA[flammenvogel]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:37:33 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:39:01 GMT]]></title><description><![CDATA[<p>Ich benutze AQtime. Ist aber kommerziell. Ansonsten hätte ich jetzt auch den AMD CodeAnalyst vorgeschlagen, der ist kostenlos. Habe ich zwar noch nicht benutzt, aber für zu Hause bereits runtergeladen.</p>
<p>Wenn es auch um Performance geht, sind die Dinger wirklich ein Muss. Bei IsZero() hätte ich zum Beispiel ansonsten NIE nachgesehen, was sich machen lässt. Und bei 19% der Gesamtzeit kann man da ja durchaus etwas rumschrauben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118193</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118193</guid><dc:creator><![CDATA[FelixManke]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:39:01 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:49:54 GMT]]></title><description><![CDATA[<p>oder <a href="http://www.intel.com/cd/software/products/asmo-na/eng/vtune/index.htm" rel="nofollow">Intel VTune</a> - laeuft nur auf intel-cpus, ist aber sehr maechtig und kostet geld.<br />
der code analyst laeuft ueberall.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118195</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118195</guid><dc:creator><![CDATA[hellihjb]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:49:54 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 10:47:49 GMT]]></title><description><![CDATA[<p>Also ich wollte eigentlich kein Geld dafür ausgeben, ich lade mir jetzt erstmal dieses Tool von Amd runter. Die große Frage ist nur ob das auf Intel CPUs funktioniert/Probleme macht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118202</guid><dc:creator><![CDATA[flammenvogel]]></dc:creator><pubDate>Wed, 16 Aug 2006 10:47:49 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 12:15:25 GMT]]></title><description><![CDATA[<p>Um nochmal auf meinen Test zurückzukommen :). Hab nochmal nen Test gemacht mit der Assembler-Version:</p>
<pre><code class="language-cpp">bool IsZero1(float f)
{
    return fabs(f) &lt;= CUtils::ZERO;
};
bool IsZero1Asm(float f)
{
    bool result;
    _asm 
    {
        xor     bl,bl
        fld     f
        fabs
        fcomp   CUtils::ZERO
        fstsw   ax
        fwait    
        sahf      
        adc     bl,0
        mov     result,bl
    };
    return result;
};
bool IsZero2(float f)
{
    return (f &gt;= -CUtils::ZERO) &amp;&amp; (f &lt;= CUtils::ZERO);
};
</code></pre>
<p>Ergebnisse (100000000 Durchläufe):</p>
<p>IsZero1(): 11,70925581<br />
IsZero1Asm(): 5,12243133<br />
IsZero2(): 4,59284843</p>
<p>Fazit: Der Unterschied zwischen selbst kontrolliertem fabs (IsZero1Asm) und Variante zwei ist ziemlich gering. Die Implementierung von Microsoft fabs() macht offenbar interessante Sachen...</p>
<p>Gib's noch ne Assembler-Variante zu IsZero2()?? Und wie ist der Code für gcc? Und Inkompatibilitäten habe ich nicht zu befüchten, sofern ich für nen x86er kompiliere? Gibt's da nen Compiler-Define, was man abfragen kann? Dann könnte man sowas machen wie</p>
<pre><code class="language-cpp">#ifdef _X86 &amp;&amp; _GCC
asm mit '%'
#elif _X86 &amp;&amp; _MSC_VER
asm ohne '%'
#else
normal 
#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1118293</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118293</guid><dc:creator><![CDATA[FelixManke]]></dc:creator><pubDate>Wed, 16 Aug 2006 12:15:25 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 12:25:45 GMT]]></title><description><![CDATA[<p>das waere vielleicht noch einen test wert:</p>
<pre><code>float EPS= 0.0001f;
inline bool zero(float a)
{
	_asm {
		mov ecx,a
		xor eax,eax
		and ecx,0x7fffffff
		sub ecx,EPS
		adc eax,0
	};
}
</code></pre>
<p>voraussetzung ist, dass &quot;EPS&quot; positiv ist.<br />
da (positive) wachsende floating-point-zahlen in ihrer binaer-repraesentation streng monoton steigend sind, kann man sich das auslesen der fpu-flags sparen...</p>
<p>bzgl gcc gibt's irgendwelche flags die auch inline-assembler mit intel-syntax erlauben, hab's aber auch nicht mehr im kopf - muesste sich per suche finden lassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118300</guid><dc:creator><![CDATA[hellihjb]]></dc:creator><pubDate>Wed, 16 Aug 2006 12:25:45 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 12:30:23 GMT]]></title><description><![CDATA[<p>hellihjb schrieb:</p>
<blockquote>
<p>das waere vielleicht noch einen test wert:</p>
<pre><code>float EPS= 0.0001f;
inline bool zero(float a)
{
	_asm {
		mov ecx,a
		xor eax,eax
		and ecx,0x7fffffff
		sub ecx,EPS
		adc eax,0
	};
}
</code></pre>
<p>voraussetzung ist, dass &quot;EPS&quot; positiv ist.</p>
</blockquote>
<p>Äh, fehlt da nicht noch ein <em>bool result;</em> über und nen <em>mov result,eax</em> im asm block? Und EPS ist doch positiv. Ist doch oben definiert. Wobei ich den code so gar nicht verstehe :)...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118310</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118310</guid><dc:creator><![CDATA[FelixManke]]></dc:creator><pubDate>Wed, 16 Aug 2006 12:30:23 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 12:39:33 GMT]]></title><description><![CDATA[<p>Der &quot;Trick&quot; ist hier, dass eax das Register ist in dem der Return-Wert transportiert wird. Brauchst also eax nicht nochmal nach eax kopieren <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/1118319</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118319</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Wed, 16 Aug 2006 12:39:33 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 12:46:31 GMT]]></title><description><![CDATA[<p>das können wir sogar ohne inline-assembler machen:</p>
<pre><code class="language-cpp">inline bool zero(const float&amp; a)
{
	static const float eps = 0.0001f;
	return (reinterpret_cast&lt;const unsigned&amp;&gt;(a)&amp;(~0u&gt;&gt;1))&lt;reinterpret_cast&lt;const unsigned&amp;&gt;(eps);
}
</code></pre>
<p>der erzeugte code ist ggf. sogar noch effizienter. das ist mal ein seltener fall, wo es sich lohnt, builtins als referenz-auf-const zu übergeben, da die funktion eigentlich gar nicht mit dem argument in form eine floats arbeitet - jedenfalls verbleibt mit vc2005ee bei einfacher übergabe als float selbst bei höchster optimierung noch eine fld/fstp kombination, wenn das argument per value übergeben wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118320</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118320</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 16 Aug 2006 12:46:31 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 12:48:29 GMT]]></title><description><![CDATA[<p>das &quot;&lt;&quot; wird aber wahrscheinlich wieder in einen conditional-branch uebersetzt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118336</guid><dc:creator><![CDATA[hellihjb]]></dc:creator><pubDate>Wed, 16 Aug 2006 12:48:29 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 12:54:15 GMT]]></title><description><![CDATA[<p>Also der VC++2005 macht aus camper's Beispiel (im Kontext einer if-Condition) folgendes.</p>
<pre><code class="language-cpp">float f;
if (zero(f)) {
}
</code></pre>
<pre><code>00401011  mov         ecx,dword ptr [esp] 
00401014  and         ecx,7FFFFFFFh 
0040101A  cmp         ecx,38D1B717h 
00401020  jae         main+31h (401031h)
</code></pre>
<p>Jap, das <strong>ist</strong> effizienter <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>
<p>EDIT:<br />
Feststellung: Ein gut optimierender Compiler hat schon was.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1118343</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118343</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Wed, 16 Aug 2006 12:54:15 GMT</pubDate></item><item><title><![CDATA[Reply to Performance von Test gegen Null mit kleinem Epsilon für floats on Wed, 16 Aug 2006 12:54:03 GMT]]></title><description><![CDATA[<p>hellihjb schrieb:</p>
<blockquote>
<p>das &quot;&lt;&quot; wird aber wahrscheinlich wieder in einen conditional-branch uebersetzt...</p>
</blockquote>
<p>zum glück gibt es seit ewigkeiten (PPro) die set<em>cc</em> befehle <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/1118346</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1118346</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 16 Aug 2006 12:54:03 GMT</pubDate></item></channel></rss>