So I have two versions of a hydrodynamic code that has the same underlying physics. Lets call them code A and B. However code B is more optimized and more object oriented. I was trying to compare the numerical results of both codes and see if they seem compatible. The way I'm doing this is running both codes with the same initial parameters and calculating a particular hydrodynamic value X.

X is in the order of magnitude of 1E6. To compare both codes I'm essentially doing $$X(A)-X(B)= \epsilon,$$ where $\epsilon$ is some error. The test is giving $\epsilon=10^{-2}$.

This would mean that both codes spit out the same X for the first 8 digits.

How significant is this error? I'm using double precision for non-integers, would such a magnitude simply imply a cumulative round off error for the thousands of calculations involved in a hydro code? Or a fundamental difference I'm missing?

  • 4
    $\begingroup$ One cannot say much based on one number. Thus, it might be that the difference in implementation causes some additional floating point error or with an equal probability there can be a fundamental error in one of the codes. The best way of verifying numerical methods is to find mathematically proven facts regarding the convergence rates of the used techniques and check those numerically. More than once I have managed to get a correct solution with accuracy of multiple digits but could not achieve more due to minor implementation errors. $\endgroup$
    – knl
    Nov 8, 2015 at 1:08

1 Answer 1


If two different codes agree to 8 digits on some non-trivial quantity, then that is far better than you'd expect in almost all cases. However, there are some cases where the quantity $X$ is poorly chosen, and consequently not indicative. For example, if you considered the total mass in a simulation, then two codes that are both conservative might give the same answer, but differ in almost every other aspect of the solutions they produce. In other words, the choice of $X$ matters. But if your answers are the same to 8 digits, then you're more than likely on the right track with both codes (or they both contain the exact same bug).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.