<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: 3.5 &#8212; Relational operators (comparisons)</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/</link>
	<description></description>
	<pubDate>Mon, 13 Oct 2008 11:30:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Stuart</title>
		<link>http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-20724</link>
		<dc:creator>Stuart</dc:creator>
		<pubDate>Fri, 11 Jul 2008 11:08:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-20724</guid>
		<description>Sorry, LOL. I'd been struggling with it for a while trying to fully understand how it works. . . .


PS. I wouldn't've been able to code that function without your teachings. ;D</description>
		<content:encoded><![CDATA[<p>Sorry, LOL. I&#8217;d been struggling with it for a while trying to fully understand how it works. . . .</p>
<p>PS. I wouldn&#8217;t've been able to code that function without your teachings. ;D</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-20676</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Fri, 11 Jul 2008 01:47:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-20676</guid>
		<description>I didn't write that function, Donald Knuth did. :)  You're correct in that it isn't symmetric though.  I'm not sure why your tags aren't working either.  Seems to work for some people and not others and I still haven't isolated why.</description>
		<content:encoded><![CDATA[<p>I didn&#8217;t write that function, Donald Knuth did. :)  You&#8217;re correct in that it isn&#8217;t symmetric though.  I&#8217;m not sure why your tags aren&#8217;t working either.  Seems to work for some people and not others and I still haven&#8217;t isolated why.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart</title>
		<link>http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-20063</link>
		<dc:creator>Stuart</dc:creator>
		<pubDate>Sun, 29 Jun 2008 21:06:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-20063</guid>
		<description>BTW, I wish my tags would work. Don't know what the problem is. : (</description>
		<content:encoded><![CDATA[<p>BTW, I wish my tags would work. Don&#8217;t know what the problem is. : (</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart</title>
		<link>http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-20061</link>
		<dc:creator>Stuart</dc:creator>
		<pubDate>Sun, 29 Jun 2008 21:04:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-20061</guid>
		<description>Alex, you've made an error in your IsEqual function.
With a dEpsilon of 0.1, if dX is 150 and dY is 135, it will evaluate to true; but if dX is 135 and dY is 150 (the other way round), it will evaluate to false. 
This is because your dEpsilon is only working on dX; not both dX and dY.


I've rewrote your function like this:

bool IsEqual(double dX, double dY)   
{   
    const double dEpsilon = 1; // dX and dY have to be within 1% of eachother 
    return fabs(dX - dY) &#60;= dEpsilon * ((dX + dY) / 100);   
}

I've tested this and it works fine. (99 will equal 100, but 98 will not equal 100.)

; )</description>
		<content:encoded><![CDATA[<p>Alex, you&#8217;ve made an error in your IsEqual function.<br />
With a dEpsilon of 0.1, if dX is 150 and dY is 135, it will evaluate to true; but if dX is 135 and dY is 150 (the other way round), it will evaluate to false.<br />
This is because your dEpsilon is only working on dX; not both dX and dY.</p>
<p>I&#8217;ve rewrote your function like this:</p>
<p>bool IsEqual(double dX, double dY)<br />
{<br />
    const double dEpsilon = 1; // dX and dY have to be within 1% of eachother<br />
    return fabs(dX - dY) &lt;= dEpsilon * ((dX + dY) / 100);<br />
}</p>
<p>I&#8217;ve tested this and it works fine. (99 will equal 100, but 98 will not equal 100.)</p>
<p>; )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 3.4 &#8212; Sizeof, comma, and arithmetic if operators</title>
		<link>http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-12643</link>
		<dc:creator>Learn C++ - &#187; 3.4 &#8212; Sizeof, comma, and arithmetic if operators</dc:creator>
		<pubDate>Wed, 23 Apr 2008 02:36:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-12643</guid>
		<description>[...]  3.5 â€” Relational operators (comparisons) [...]</description>
		<content:encoded><![CDATA[<p>[...]  3.5 â€” Relational operators (comparisons) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learn C++ - &#187; 3.6 &#8212; Logical operators</title>
		<link>http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-12611</link>
		<dc:creator>Learn C++ - &#187; 3.6 &#8212; Logical operators</dc:creator>
		<pubDate>Wed, 23 Apr 2008 01:52:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-12611</guid>
		<description>[...] 2007      Prev/Next Posts   &#171; 3.5 &#8212; Relational operators (comparisons) &#124; Home &#124; 3.7 &#8212; Converting between binary and decimal &#187;     Friday, June 15th, 2007 at [...]</description>
		<content:encoded><![CDATA[<p>[...] 2007      Prev/Next Posts   &laquo; 3.5 &#8212; Relational operators (comparisons) | Home | 3.7 &#8212; Converting between binary and decimal &raquo;     Friday, June 15th, 2007 at [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-38</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Wed, 20 Jun 2007 01:05:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-38</guid>
		<description>A float is not accurate to 7 decimal places.  A float is accurate to approximately 7 significant digits.  A significant digits is any digit that is not a placeholder 0, including ones on the left side of the decimal.

For example, .0095 has two placeholder zeros, and so is only 2 significant figures.  34.90 has 4 significant figures.

There are two types of errors we need to watch out for with floating point values: rounding errors, and precision errors.

Rounding errors can happen with numbers of any length, because some numbers have infinite representations in binary (0.1 for example), and those representations will be truncated.  Rounding errors typically make your answer wrong by 0.000001, or some small number like that.

The second and more potentially serious error are precision errors, where your number can't be stored because the floating point representation doesn't have enough memory.  Precision errors are more serious because they can affect your answer by a much larger degree of magnitude than rounding errors.

0.0095 * 36.75 = 0.349125, which is 6 significant figures, so in this case, you'll probably be fine in terms of precision errors.    Consequently, your answer will only be affected by small rounding errors.

But consider a case like: 0.0095 * 36.7513.  Even though 36.7513 is 4 decimal places, it's 6 significant digits.  When multiplied by 0.0095, the answer is 0.34913735.  A float will truncate this to 0.349137.

Once you get into larger dollar amounts, floats are even less suitable.  Consider $100264.75.  This is a number with 8 significant digits, even though it only uses 2 decimal places.  Already a float is not going to be able to hold this number.  As you do mathematical operations on it, it's going to drift farther and farther from your intended answer.

In short, if accuracy is important, use double.  Only use floats when accuracy is not that important (eg. in games, where it doesn't really matter if your character has 137.24 or 137.25 strength).</description>
		<content:encoded><![CDATA[<p>A float is not accurate to 7 decimal places.  A float is accurate to approximately 7 significant digits.  A significant digits is any digit that is not a placeholder 0, including ones on the left side of the decimal.</p>
<p>For example, .0095 has two placeholder zeros, and so is only 2 significant figures.  34.90 has 4 significant figures.</p>
<p>There are two types of errors we need to watch out for with floating point values: rounding errors, and precision errors.</p>
<p>Rounding errors can happen with numbers of any length, because some numbers have infinite representations in binary (0.1 for example), and those representations will be truncated.  Rounding errors typically make your answer wrong by 0.000001, or some small number like that.</p>
<p>The second and more potentially serious error are precision errors, where your number can&#8217;t be stored because the floating point representation doesn&#8217;t have enough memory.  Precision errors are more serious because they can affect your answer by a much larger degree of magnitude than rounding errors.</p>
<p>0.0095 * 36.75 = 0.349125, which is 6 significant figures, so in this case, you&#8217;ll probably be fine in terms of precision errors.    Consequently, your answer will only be affected by small rounding errors.</p>
<p>But consider a case like: 0.0095 * 36.7513.  Even though 36.7513 is 4 decimal places, it&#8217;s 6 significant digits.  When multiplied by 0.0095, the answer is 0.34913735.  A float will truncate this to 0.349137.</p>
<p>Once you get into larger dollar amounts, floats are even less suitable.  Consider $100264.75.  This is a number with 8 significant digits, even though it only uses 2 decimal places.  Already a float is not going to be able to hold this number.  As you do mathematical operations on it, it&#8217;s going to drift farther and farther from your intended answer.</p>
<p>In short, if accuracy is important, use double.  Only use floats when accuracy is not that important (eg. in games, where it doesn&#8217;t really matter if your character has 137.24 or 137.25 strength).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cpptrader</title>
		<link>http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-37</link>
		<dc:creator>cpptrader</dc:creator>
		<pubDate>Tue, 19 Jun 2007 19:27:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/35-relational-operators-comparisons/#comment-37</guid>
		<description>If a float is generally accurate to 7 decimal places, and a double is at 16, if I were working with figures with 2 or 4 decimal places, would the accuracy ever really be an issue?  For example, would I see something like
(.0095 * 36.75) &#62; 34.90 
equate to false since it uses less than the 7 decimals that floats tend to be accurate to?</description>
		<content:encoded><![CDATA[<p>If a float is generally accurate to 7 decimal places, and a double is at 16, if I were working with figures with 2 or 4 decimal places, would the accuracy ever really be an issue?  For example, would I see something like<br />
(.0095 * 36.75) &gt; 34.90<br />
equate to false since it uses less than the 7 decimals that floats tend to be accurate to?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
