title: If I have two programs that produce the same out using doubles can I assume both programs are identical?
body: <p>I'm writing a C++ program and in an attempt to fix a bug I've isolated a section of my main program into a separate file. <em>I'll call the main program <strong>Prog1</strong> and the separated section <strong>Prog2</strong>.</em></p>
  
  <p>I've managed to successfully find and fix the bug in Prog2 and I've copied the changes over to Prog1. When I run everything the two programs output the same result <strong><em>IFF</em></strong> the only data type I'm using in both programs is type <code>double</code>.</p>
  
  <p>I was hoping to change all doubles to <code>long double</code> for increased precision but in doing so, the output of Prog1 is slightly different than Prog2.</p>
  
  <p>My thinking is that this is an issue of <em>promotion</em> because certain calculations in Prog1 use long doubles whereas in Prog2 I occasionally just use literals. For example:</p>
  
  <p><strong>Prog1:</strong></p>
  
  <pre><code>long double num = 1.0;
  
  value1 = num + 2.0;
  </code></pre>
  
  <p><strong>Prog2:</strong></p>
  
  <pre><code>value2 = 1.0 + 2.0;
  </code></pre>
  
  <p>Where the results of <code>value1</code> and <code>value2</code> will not be exactly equal (see: <a href="https://stackoverflow.com/questions/588004/is-floating-point-math-broken">Is floating point math broken?</a>).</p>
  
  <p>Now I could just change every literal in both programs to type <code>long double</code> (e.g. <code>1.0L</code>) then see if the outputs match but unfortunately, that's easier said than done (there are <strong><em>a lot</em></strong>).</p>
  
  <p>So my question is:</p>
  
  <p><strong>Since the output of my two programs exactly matches when using doubles, is it safe to assume Prog1 is functioning correctly if Prog2 is? Even though the results differ when using long doubles?</strong></p>