Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy would the same code yield different numeric results on 32 vs 64-bit machines?
    primarykey
    data
    text
    <p>We are working on a library of numeric routines in C. We are not sure yet whether we will work with single precision (<code>float</code>) or double (<code>double</code>), so we've defined a type <code>SP</code> as an alias until we decide:</p> <pre><code>typedef float SP; </code></pre> <p>When we run our unit tests, they all pass on my machine (a 64-bit Ubuntu) but they fail on my colleague's (a 32-bit Ubuntu that was mistakenly installed on a 64-bit machine).</p> <p>Using Git's <code>bisect</code> command, we found the exact diff that began yielding different results between his machine and mine:</p> <pre><code>-typedef double SP; +typedef float SP; </code></pre> <p>In other words, going from double precision to single precision yields numerically different results on our machines (about 1e-3 relative difference in the worst cases).</p> <p>We are fairly certain that we are never comparing unsigned ints to negative signed ints anywhere.</p> <p><strong>Why would a library of numeric routines yield different results on a 32-bit operating system and on a 64-bit system?</strong></p> <p><strong>CLARIFICATION</strong></p> <p>I'm afraid I might not have been clear enough: we have Git commit <code>2f3f671</code> that uses double precision, and where the unit tests pass equally well on both machines. Then we have Git commit <code>46f2ba</code>, where we changed to single precision, and here the tests <em>still</em> pass on the 64-bit machine but <em>not</em> on the 32-bit machine.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload