<p>I did this Just for kicks (so, not exactly a question, i can see the downmodding happening already) but, in lieu of Google's newfound <a href="http://www.google.com/search?hl=en&amp;q=1999999999999999-1999999999999995&amp;btnG=Search" rel="nofollow noreferrer">inability</a> to do <a href="http://www.google.com/search?hl=en&amp;q=400000000000002-400000000000001&amp;btnG=Search" rel="nofollow noreferrer">math</a> <a href="http://www.google.com/search?hl=en&amp;q=10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000&amp;btnG=Search" rel="nofollow noreferrer">correctly</a> (check it! according to google 500,000,000,000,002 - 500,000,000,000,001 = 0), i figured i'd try the following in C to run a little theory.</p>

<pre><code>int main()
{
   char* a = "399999999999999";
   char* b = "399999999999998";

   float da = atof(a);
   float db = atof(b);

   printf("%s - %s = %f\n", a, b, da-db);

   a = "500000000000002";
   b = "500000000000001";
   da = atof(a);
   db = atof(b);
   printf("%s - %s = %f\n", a, b, da-db);
}
</code></pre>

<p>When you run this program, you get the following</p>

<pre><code>   399999999999999 - 399999999999998 = 0.000000
   500000000000002 - 500000000000001 = 0.000000
</code></pre>

<p>It would seem like Google is using simple 32 bit floating precision (the error here), if you switch float for double in the above code, you fix the issue! Could this be it?</p>

<p>/mp</p>

[{'answer_id': 27105, 'author': 'Frank Krueger', 'author_id': 338, 'author_profile': 'https://Stackoverflow.com/users/338', 'pm_score': 2, 'selected': False, 'text': '<p>For more of this kind of silliness see this nice article pertaining to Windows calculator.</p>\n\n<p><a href="http://blogs.msdn.com/oldnewthing/archive/2004/05/25/141253.aspx" rel="nofollow noreferrer">When you change the insides, nobody notices</a></p>\n\n<blockquote>\n  <p>The innards of Calc - the arithmetic\n  engine - was completely thrown away\n  and rewritten from scratch. The\n  standard IEEE floating point library\n  was replaced with an\n  arbitrary-precision arithmetic\n  library. This was done after people\n  kept writing ha-ha articles about how\n  Calc couldn\'t do decimal arithmetic\n  correctly, that for example computing\n  10.21 - 10.2 resulted in 0.0100000000000016.</p>\n</blockquote>\n'}, {'answer_id': 27545, 'author': 'DrPizza', 'author_id': 2131, 'author_profile': 'https://Stackoverflow.com/users/2131', 'pm_score': 2, 'selected': False, 'text': '<blockquote>\n  <p>It would seem like Google is using simple 32 bit floating precision (the error here), if you switch float for double in the above code, you fix the issue! Could this be it?</p>\n</blockquote>\n\n<p>No, you just defer the issue.  doubles still exhibit the same issue, just with larger numbers.</p>\n'}, {'answer_id': 27552, 'author': 'gil', 'author_id': 195, 'author_profile': 'https://Stackoverflow.com/users/195', 'pm_score': 3, 'selected': True, 'text': '<p>in C#, try (double.maxvalue == (double.maxvalue - 100)) , you\'ll get true ...</p>\n\n<p>but thats what it is supposed to be:</p>\n\n<p><a href="http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems</a> </p>\n\n<p>thinking about it, you have 64 bit representing a number greater than 2^64 (double.maxvalue), so inaccuracy is expected. </p>\n'}, {'answer_id': 28443, 'author': 'Derek Park', 'author_id': 872, 'author_profile': 'https://Stackoverflow.com/users/872', 'pm_score': 1, 'selected': False, 'text': "<p>@ebel</p>\n\n<blockquote>\n  <p>thinking about it, you have 64 bit representing a number greater than 2^64 (double.maxvalue), so inaccuracy is expected. </p>\n</blockquote>\n\n<p>2^64 is not the maximum value of a double.  2^64 is the number of unique values that a double (or any other 64-bit type) can hold.  <code>Double.MaxValue</code> is equal to 1.79769313486232e308.</p>\n\n<p>Inaccuracy with floating point numbers doesn't come from representing values larger than <code>Double.MaxValue</code> (which is impossible, excluding <code>Double.PositiveInfinity</code>).  It comes from the fact that the desired range of values is simply too large to fit into the datatype.  So we give up precision in exchange for a larger effective range.  In essense, we are dropping significant digits in return for a larger exponent range.</p>\n\n<p>@DrPizza</p>\n\n<blockquote>\n  <p>Not even; the IEEE encodings use multiple encodings for the same values. Specifically, NaN is represented by an exponent of all-bits-1, and then any non-zero value for the mantissa. As such, there are 252 NaNs for doubles, 223 NaNs for singles.</p>\n</blockquote>\n\n<p>True.  I didn't account for duplicate encodings.  There are actually 2<sup>52</sup>-1 NaNs for doubles and 2<sup>23</sup>-1 NaNs for singles, though.  :p</p>\n"}, {'answer_id': 28625, 'author': 'DrPizza', 'author_id': 2131, 'author_profile': 'https://Stackoverflow.com/users/2131', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n  <p>2^64 is not the maximum value of a double. 2^64 is the number of unique values that a double (or any other 64-bit type) can hold. Double.MaxValue is equal to 1.79769313486232e308.</p>\n</blockquote>\n\n<p>Not even; the IEEE encodings use multiple encodings for the same values.  Specifically, NaN is represented by an exponent of all-bits-1, and then <em>any</em> non-zero value for the mantissa. As such, there are 2<sup>52</sup> NaNs for doubles, 2<sup>23</sup> NaNs for singles.</p>\n'}, {'answer_id': 29039, 'author': 'DrPizza', 'author_id': 2131, 'author_profile': 'https://Stackoverflow.com/users/2131', 'pm_score': 0, 'selected': False, 'text': "<blockquote>\n  <p>True. I didn't account for duplicate encodings. There are actually 252-1 NaNs for doubles and 223-1 NaNs for singles, though. :p</p>\n</blockquote>\n\n<p>Doh, forgot to subtract the infinities.</p>\n"}, {'answer_id': 60138, 'author': 'John Meagher', 'author_id': 3535, 'author_profile': 'https://Stackoverflow.com/users/3535', 'pm_score': 0, 'selected': False, 'text': "<p>The rough estimate version of this issue that I learned is that 32-bit floats give you 5 digits of precision and 64-bit floats give you 15 digits of precision.  This will of course vary depending on how the floats are encoded, but it's a pretty good starting point.  </p>\n"}]
['https://Stackoverflow.com/questions/27095', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/547/']