Thanks to @John for pointing out a very complete article about floating point arithmetics.
It turns out that, when precision is needed, operations should be re-ordered, and formulas adapted to avoid loss of precision, as explained in the Cancellation chapter: when comparing numbers that are very close to each other (which is my case), "catastrophic cancellation" may occur, inducing a huge loss of precision. Often, re-writing the formula, or re-ordering operations according to your à-priori knowledge of the operands values can lead to achieving greater accuracy in calculus.
What I'll remember from this article is:
- be careful when substracting two nearly-identical quantities
- try to re-arrange operations to avoid catastrophic cancellation
For the latter case, remember that computing (x - y) * (x + y)
gives more accurate results than x * x - y * y
.