Let's say I have two numbers $x$ and $y$ which I'd like to compare to see whether they are equal up to their first $N$ digits.

For instance $ 1.002 \approx 1.001$ and $1002 \approx 1001$ up to 3 digits.

Intuitively, this means that the difference of $x$ and $y$ should be $N$ orders of magnitude smaller than (say) $x$. In symbols, the digits of accuracy, $D$ is $$ D = \log_{10}(|x|) -\log_{10} (|x-y|) = - \log_{10} \left| \frac{y}{x} - 1\right| $$

To make the definition symmetric, it seems to make sense to replace the $\frac{y}{x} - 1$ by $\ln(\frac{y}{x})$.

So a final definition would be

$$ D = \begin{cases} -\log_{10} \left| \ln |x| - \ln |y| \right| & \text{ if } xy > 0 \\ -\infty & \text{ otherwise } \end{cases}$$

Is this a reasonable definition? If so, does it have a name? Where is it referenced?

  • 1
    $\begingroup$ This is essentially an extension of the definition of relative error, using the log base 10 to obtain a notion of "digits" that extends to non-integer values. I don't think it has a name, other than "the log of the relative error". $\endgroup$
    – Paul
    Commented Dec 20, 2017 at 21:38
  • 1
    $\begingroup$ So $1.004\approx 1.001$ up to 3 digits, but does $3.012 \approx 3.003$ up to 3 digits (same relative error)? $\endgroup$
    – Kirill
    Commented Dec 20, 2017 at 22:17
  • $\begingroup$ 1100 ≈ 1099 giving D=3.04 makes more sense if you take it to mean "x and y will match once they are both rounded to N digits". 3.012≈3.003 actually gives D=2.52 which brings up the question: Should D be rounded up or down before using it as N? $\endgroup$ Commented Dec 21, 2017 at 2:41

1 Answer 1


Short version

In scientific computing, the notion of relative error is way more popular than accuracy to $N$ digits. Whenever we present the results, we usually plot the obtained (scaled) data and relative/absolute error in multiple different ways. Reporting the number of correct obtained digits (in addition to the relative error) is usually limited to the following scenarios:

  1. In a table form, for the column "number of digits".
  2. In a sentence of the type: "...this method allowed to obtain a $K$-digit accurate solution...".

For both cases, I can hardly imagine the value of providing a counter-intuitive, non-integer value.

Moreover (since we usually prefer to think in base 10), one finds the quantity $D$ as: $$ D = -\log_{10}\left(\frac{|x-y|}{|x|}\right)=-\log_{10}(\eta) $$

where $x$ is the test value, $y$ is the reference value, and $\eta$ is the relative error between the two. Without loss of generality, let's not touch cases when $x=0$ and $xy<0$ ($x$ and $y$ have different signs).

However, knowing $D$ does not give me an immediate answer to the question of how many correct digits $x$ has. Simply, because $D$ is not an integer, and the answer to this question (usually) implies an integer answer. $D$ can tell me that $x$ has at least $\lfloor D \rfloor$ and at most $\lceil D\rceil$ correct digits, reducing the uncertainty to two possible answers.

For a more elaborate derivation & discussion on this part and how this is justified, see this question on Math SE.

Is it possible to decide solely on $D$ (or $\eta$), how many digits are correct? No.

The comments provide counterexamples (explained by the above paragraph): $$ x_1 = 1.004,\quad y_1 = 1.001,\quad \eta_1 \approx 2.988\cdot10^{-3},\quad D_1 = 2.5246...\\ x_2 = 3.012,\quad y_2 = 3.003,\quad \eta_2 \approx 2.988\cdot10^{-3},\quad D_2 = 2.5246... $$ Here, $D_1=D_2$, but

  • In case of $(x_1,y_1)$, $D_1$ has to be ceiled to get the correct answer of 3-digit match
  • In case of $(x_2,y_2)$, $D_2$ has to be floored to get the correct answer of 2-digit match

So, the definition of $D$ in extended to a non-integer number of digits sense is counterintuitive and hard to rely upon.

Now, to always be correct one may answer that: $x$ is at least $\lfloor D \rfloor$-digit accurate wrt $y$. That implies the following conclusion: if one has a method that provides a $10^{-3}$-level relative error, that leaves us with a 2-digit accurate solution. Even though, in some cases, it might be 3-digit accurate.


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.