<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Floating point woes - C++ - tribe.net</title>
    <link>http://cpp.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478?format=rss</link>
    <description>Tribe.net. Local Connections</description>
    <item>
      <title>Re: Floating point woes</title>
      <link>http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#72442175-3036-4bd0-ab46-fc3e9d11a85c</link>
      <description>Ah-ha!   Beautiful!  Thank you very much!</description>
      <pubDate>Tue, 05 Sep 2006 19:26:35 GMT</pubDate>
      <guid isPermaLink="false">http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#72442175-3036-4bd0-ab46-fc3e9d11a85c</guid>
      <dc:creator>$item.owner.firstName</dc:creator>
      <dc:date>2006-09-05T19:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Floating point woes</title>
      <link>http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#2c8a43a8-43a3-4179-9573-c7ef4c621d87</link>
      <description>1, 10000, and 200000 are all integers, so the math is done using integers.  Then the result (0) is converted to a double when assigned to 'test'&#xD;
&#xD;
It needs to look like this:&#xD;
test = (1.0 / 10000.0) + (1.0 / 200000.0);&#xD;
&#xD;
If you are using variables, make sure they are cast to doubles, for example:&#xD;
int i  = 10000;&#xD;
&#xD;
test = 1.0 / (double)i;</description>
      <pubDate>Mon, 04 Sep 2006 17:39:51 GMT</pubDate>
      <guid isPermaLink="false">http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#2c8a43a8-43a3-4179-9573-c7ef4c621d87</guid>
      <dc:creator>Scott</dc:creator>
      <dc:date>2006-09-04T17:39:51Z</dc:date>
    </item>
    <item>
      <title>Floating point woes</title>
      <link>http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#61339422-e345-4fe7-aaa6-548597cf39ad</link>
      <description>I'm writing a few short programs based on calculating factors in electronics.  &#xD;
&#xD;
As such, I often have to multiply and divide some small numbers, and the round-off is of such a magnitude that it renders the calculations useless.&#xD;
&#xD;
For instance, with this fragment of code:&#xD;
&#xD;
#include &amp;amp;lt;iostream&gt;&#xD;
using namespace std;&#xD;
int main () {&#xD;
&#xD;
double test;&#xD;
test = ( 1 / 10000) + ( 1 / 200000);&#xD;
cout &gt;&gt; test;&#xD;
return 0;&#xD;
}&#xD;
&#xD;
The output will give me zero.</description>
      <pubDate>Mon, 04 Sep 2006 16:57:37 GMT</pubDate>
      <guid isPermaLink="false">http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#61339422-e345-4fe7-aaa6-548597cf39ad</guid>
      <dc:creator>$item.owner.firstName</dc:creator>
      <dc:date>2006-09-04T16:57:37Z</dc:date>
    </item>
  </channel>
</rss>



