<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Floating point woes - C++ - tribe.net</title>
  <link rel="alternate" href="http://cpp.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478?format=atom" />
  <subtitle>Tribe.net. Local Connections</subtitle>
  <entry>
    <title>Re: Floating point woes</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#72442175-3036-4bd0-ab46-fc3e9d11a85c" />
    <author>
      <name>$item.owner.firstName</name>
    </author>
    <id>http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#72442175-3036-4bd0-ab46-fc3e9d11a85c</id>
    <updated>2006-09-05T19:26:35Z</updated>
    <published>2006-09-05T19:26:35Z</published>
    <summary type="html">Ah-ha!   Beautiful!  Thank you very much!</summary>
    <dc:creator>$item.owner.firstName</dc:creator>
    <dc:date>2006-09-05T19:26:35Z</dc:date>
  </entry>
  <entry>
    <title>Re: Floating point woes</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#2c8a43a8-43a3-4179-9573-c7ef4c621d87" />
    <author>
      <name>Scott</name>
    </author>
    <id>http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#2c8a43a8-43a3-4179-9573-c7ef4c621d87</id>
    <updated>2006-09-04T17:39:51Z</updated>
    <published>2006-09-04T17:39:51Z</published>
    <summary type="html">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;</summary>
    <dc:creator>Scott</dc:creator>
    <dc:date>2006-09-04T17:39:51Z</dc:date>
  </entry>
  <entry>
    <title>Floating point woes</title>
    <link rel="alternate" href="http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#61339422-e345-4fe7-aaa6-548597cf39ad" />
    <author>
      <name>$item.owner.firstName</name>
    </author>
    <id>http://CPP.tribe.net/thread/a8c464ea-84bf-45ad-9573-e29cc25e9478#61339422-e345-4fe7-aaa6-548597cf39ad</id>
    <updated>2006-09-04T16:57:37Z</updated>
    <published>2006-09-04T16:57:37Z</published>
    <summary type="html">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.</summary>
    <dc:creator>$item.owner.firstName</dc:creator>
    <dc:date>2006-09-04T16:57:37Z</dc:date>
  </entry>
</feed>



