<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Library of Graphics &#187; General C++</title>
	<atom:link href="http://libg.org/category/general-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://libg.org</link>
	<description>Computer Graphics: Fundamental and Practice</description>
	<lastBuildDate>Mon, 23 Mar 2009 03:12:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Floating-point: Bit Value of INF, NAN, DEN</title>
		<link>http://libg.org/2008/09/26/floating-point-bit-value-of-inf-nan-den/</link>
		<comments>http://libg.org/2008/09/26/floating-point-bit-value-of-inf-nan-den/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 04:55:22 +0000</pubDate>
		<dc:creator>Mason</dc:creator>
				<category><![CDATA[General C++]]></category>
		<category><![CDATA[Numeral]]></category>
		<category><![CDATA[floating point]]></category>

		<guid isPermaLink="false">http://libg.org/2008/09/26/floating-point-bit-value-of-inf-nan-den/</guid>
		<description><![CDATA[I have every write a post and mentioned a little bit about the binary format of IEEE 754 in Comparison of Float and Double Precision. In this post I made a table to indicate the details of bit values for the IEEE 754 32bit single-precision float, the bit values of some special floating point value, including Zero, One, Minus One, ...]]></description>
			<content:encoded><![CDATA[<p>I have every write a post and mentioned a little bit about the binary format of <a href="http://en.wikipedia.org/wiki/IEEE_754" target="_blank">IEEE 754</a> in <a href="http://libg.org/2008/09/07/comparison-of-float-and-double-precision/" target="_blank">Comparison of Float and Double Precision</a>. In this post I made a table to indicate the details of bit values for the IEEE 754 32bit single-precision float, the bit values of some special floating point value, including Zero, One, Minus One, Smallest <a href="http://en.wikipedia.org/wiki/Denormal_number" target="_blank">denormalized number</a>, &#8220;Middle&#8221; denormalized number, Largest denormalized number, Smallest normalized number, Largest normalized number, Positive infinity, Negative infinity, Not a number (NaN).</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" src="http://libg.org/wp-content/uploads/2008/09/capture-2008-09-26-131257.png" border="0" alt="Capture 2008-09-26 13.12.57" width="1025" height="596" /></p>
<p>In the column &#8220;Watch in Windows&#8221;, I put what I can see from the watch window in Visual Studio 2008 (Visual C++ Environment).</p>
]]></content:encoded>
			<wfw:commentRss>http://libg.org/2008/09/26/floating-point-bit-value-of-inf-nan-den/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Performance: encapsulate floating point and built-in tolerance</title>
		<link>http://libg.org/2008/09/11/performance-encapsulate-floating-point-and-built-in-tolerance/</link>
		<comments>http://libg.org/2008/09/11/performance-encapsulate-floating-point-and-built-in-tolerance/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 07:57:49 +0000</pubDate>
		<dc:creator>Mason</dc:creator>
				<category><![CDATA[General C++]]></category>
		<category><![CDATA[Numeral]]></category>

		<guid isPermaLink="false">http://libg.org/2008/09/11/performance-encapsulate-floating-point-and-built-in-tolerance/</guid>
		<description><![CDATA[When it comes to the floating point comparison with tolerance, two approaches come into my mind.
The first approach is to write inline functions and call them when compare floating point numbers. It is easy to understand and is widely used by numerous applications. Yes, it is really simple and I like it. The only concern is that I have to ...]]></description>
			<content:encoded><![CDATA[<p>When it comes to the floating point comparison with tolerance, two approaches come into my mind.</p>
<p>The first approach is to write inline functions and call them when compare floating point numbers. It is easy to understand and is widely used by numerous applications. Yes, it is really simple and I like it. The only concern is that I have to call these functions explicitly when compare two float or double variables, and I have to be aware of the code where it is necessary to compare with tolerance.</p>
<p>The second approach is to encapsulation floating point using a class. A float variable is the only member variable and I have to override lots of operators, assignment operator, relational and equality operators to control flow, arithmetic, unary, prefix and postfix operators. But how to implement the class is not a big deal, I&#8217;m worrying about the performance decrease which is introduced by using classes instead of pure machine data type.</p>
<p>Then I write the first to my open source library LibG, and made unit test for performance. The result looks good to me.</p>
<p><span style="text-decoration: underline">Testing Environment      <br /></span>Hardware1: CPU: AMD Sempron 2600+ (1.6G Hz). Memory: 1G, DDR400     <br />Hardware2: CPU: Intel Core2 6300 (1.86G Hz). Memory: 4G    <br />Software: Windows XP Professional with SP2</p>
<p><span style="text-decoration: underline">Testing Method</span>     <br />Repeat 15million times of a set of operations. There are one additional assignment, one comparison and one pre-decrement to complete the loop. Run 10 times and get average time.</p>
<p><span style="text-decoration: underline">Source Code      <br /></span>Open source portal of LibG: <a title="http://code.google.com/p/libg/" href="http://code.google.com/p/libg/">http://code.google.com/p/libg/</a>     <br />The class giFloat and giDouble: <a title="http://code.google.com/p/libg/source/browse/trunk/inc/gifloat.h" href="http://code.google.com/p/libg/source/browse/trunk/inc/gifloat.h">http://code.google.com/p/libg/source/browse/trunk/inc/gifloat.h</a>     <br />The testing code: <span style="text-decoration: underline"><a title="http://code.google.com/p/libg/source/browse/trunk/test/libg_unit_test/test_gifloat.cpp" href="http://code.google.com/p/libg/source/browse/trunk/test/libg_unit_test/test_gifloat.cpp">http://code.google.com/p/libg/source/browse/trunk/test/libg_unit_test/test_gifloat.cpp</a></span></p>
<p><span style="text-decoration: underline">Testing Result      <br /></span>1. Arithmetic Operations: Operations Set: +, -, *, /, +=, -=, *=, /=</p>
<table cellspacing="1" cellpadding="2" width="658" border="1">
<tbody>
<tr>
<td valign="top" align="center" width="146">Testing Result (ms)</td>
<td valign="top" align="center" width="118">float</td>
<td valign="top" align="center" width="129">giFloat</td>
<td valign="top" align="center" width="125">double</td>
<td valign="top" align="center" width="132">giDouble</td>
</tr>
<tr>
<td align="center" width="146">Hardware1</td>
<td valign="middle" align="center" width="118">856.3</td>
<td valign="middle" align="center" width="129">837.3</td>
<td valign="middle" align="center" width="125">336.1</td>
<td valign="middle" align="center" width="132">337.6</td>
</tr>
<tr>
<td align="center" width="146"><font color="#404040">Performance</font></td>
<td align="center" width="118">&#160;</td>
<td align="center" width="129"><span style="color: #008000">+2.22%</span></td>
<td valign="top" align="center" width="125">&#160;</td>
<td valign="top" align="center" width="132"><span style="color: #ff0000">-0.45%</span></td>
</tr>
<tr>
<td align="center" width="146">Hardware2</td>
<td align="center" width="118">517.2</td>
<td align="center" width="129">517.3</td>
<td valign="top" align="center" width="125">528.1</td>
<td valign="top" align="center" width="132">504.7</td>
</tr>
<tr>
<td align="center" width="146"><font color="#404040">Performance</font></td>
<td align="center" width="118">&#160;</td>
<td align="center" width="129"><font color="#ff0000">-0.02%</font></td>
<td valign="top" align="center" width="125">&#160;</td>
<td valign="top" align="center" width="132"><font color="#008000">+4.43%</font></td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="2" width="657" border="0">
<tbody>
<tr>
<td valign="top" width="655">The performance of using class is very close to machine data type.</td>
</tr>
</tbody>
</table>
<p>2. Relational and Equality Operations: Operations Set: ==, !=, &gt;, &gt;=, &lt;, &lt;=</p>
<table cellspacing="1" cellpadding="2" width="657" border="1">
<tbody>
<tr>
<td align="center" width="103">Result</td>
<td align="center" width="90">float          <br />(no tolerance)</td>
<td align="center" width="105">float          <br />(inline functions)</td>
<td align="center" width="64">giFloat</td>
<td align="center" width="89">double          <br />(no tolerance)</td>
<td align="center" width="105">double          <br />(inline functions)</td>
<td align="center" width="90">giDouble</td>
</tr>
<tr>
<td valign="top" align="center" width="104">Hardware1</td>
<td valign="top" align="center" width="90">378.1</td>
<td valign="top" align="center" width="105">667.2</td>
<td valign="top" align="center" width="64">734.4</td>
<td valign="top" align="center" width="89">270.3</td>
<td valign="top" align="center" width="105">435.9</td>
<td valign="top" align="center" width="90">482.8</td>
</tr>
<tr>
<td align="center" width="105"><font color="#404040">Performance</font></td>
<td align="center" width="90">&#160;</td>
<td align="center" width="105">&#160;</td>
<td align="center" width="64"><span style="color: #ff0000">-10.07%</span></td>
<td align="center" width="89">&#160;</td>
<td align="center" width="105">&#160;</td>
<td align="center" width="90"><span style="color: #ff0000">-9.71%</span></td>
</tr>
<tr>
<td align="center" width="105">Hardware2</td>
<td align="center" width="90">165.6</td>
<td align="center" width="105">282.8</td>
<td align="center" width="64">312.7</td>
<td align="center" width="89">151.4</td>
<td align="center" width="105">237.7</td>
<td align="center" width="90">237.3</td>
</tr>
<tr>
<td align="center" width="105"><font color="#404040">Performance</font></td>
<td align="center" width="90">&#160;</td>
<td align="center" width="105">&#160;</td>
<td align="center" width="64"><font color="#ff0000">-9.56%</font></td>
<td align="center" width="89">&#160;</td>
<td align="center" width="105">&#160;</td>
<td align="center" width="90"><font color="#008000">+0.12%</font></td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="2" width="657" border="0">
<tbody>
<tr>
<td valign="top" width="655">Comparing with using inline functions, the performance of using class decreased about 10%, it&#8217;s acceptable to me. The data type double is the most frequently used type on geometry computation, the performance result on Intel Core2 CPU is exciting.</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://libg.org/2008/09/11/performance-encapsulate-floating-point-and-built-in-tolerance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Include Guard: #pragma once vs. #ifndef #define #endif</title>
		<link>http://libg.org/2008/09/06/include-guard-pragma-once-vs-ifdef-define-endif/</link>
		<comments>http://libg.org/2008/09/06/include-guard-pragma-once-vs-ifdef-define-endif/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 04:08:38 +0000</pubDate>
		<dc:creator>Mason</dc:creator>
				<category><![CDATA[General C++]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[compile]]></category>

		<guid isPermaLink="false">http://libg.org/2008/09/06/include-guard-pragma-once-vs-ifdef-define-endif/</guid>
		<description><![CDATA[In the C and C++ programming languages, an include guard, sometimes called a macro guard, is a particular construct used to avoid the problem of double inclusion when dealing with the #include directive. The addition of include guards to a header file is one way to achieve this. pragma once is a non-standard but widely supported preprocessor directive designed to ...]]></description>
			<content:encoded><![CDATA[<p>In the C and C++ programming languages, an <strong>include guard</strong>, sometimes called a macro guard, is a particular construct used to avoid the problem of double inclusion when dealing with the #include directive. The addition of include guards to a header file is one way to achieve this. <strong>pragma once </strong>is a non-standard but widely supported preprocessor directive designed to cause the current source file to be included only once in a single compilation. Both approaches specify that the file will be included only once by the compiler when compiling a source code file.</p>
<p>The table below compared the details of <strong>pragma once</strong> and <strong>#ifndef #define #endif </strong>approach:</p>
<table border="1" cellspacing="0" cellpadding="2" width="598">
<tbody>
<tr>
<td width="157" valign="top"></td>
<td width="202" valign="top"><strong>pragma once</strong></td>
<td width="236" valign="top"><strong>#ifndef #define #endif</strong></td>
</tr>
<tr>
<td width="157" valign="top"><strong>Sample code</strong></td>
<td width="202" valign="top">
<pre name="code" class="cpp:nocontrols">
// header file
#pragma once
class foo { };
</pre>
</td>
<td width="236" valign="top">
<pre name="code" class="cpp:nocontrols">
// header file
#ifndef FOO_HEADER
#define FOO_HEADER
class foo { };
#endif // FOO_HEADER
</pre>
</td>
</tr>
<tr>
<td width="157" valign="top"><strong>C++ Standard</strong></td>
<td width="202" valign="top"><strong>No</strong></p>
<p>But both GCC and Microsoft Visual C++ support it.</td>
<td width="236" valign="top"><strong>Yes</strong></td>
</tr>
<tr>
<td width="157" valign="top"><strong>Compiling Performance</strong></td>
<td width="202" valign="top"><strong>Better</strong></p>
<p><strong></strong>This can reduce build times as the compiler will not open and read the file after the first #include of the module.</td>
<td width="236" valign="top">It will still have to open the file multiple times, and discard the guard part when compiler find the macro guard. In a large project this could cause increased compile times.</p>
<p>But you can also optimize the compiling performance of #ifdef #define #endif approach by <a href="http://www.bobarcher.org/software/include/index.html" target="_blank">this way</a>.</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://libg.org/2008/09/06/include-guard-pragma-once-vs-ifdef-define-endif/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
