Absolute and relative accuracy

Recall the grade-school approximation to the number \(\pi\).

@show p = 22/7;
p = 22 / 7 = 3.142857142857143

Not all the digits displayed for p are the same as those of \(\pi\). As an approximation, its absolute and relative accuracy are

@show abs_accuracy = abs(p-pi);
abs_accuracy = abs(p - pi) = 0.0012644892673496777
@show rel_accuracy = abs(p-pi)/pi;
rel_accuracy = abs(p - pi) / pi = 0.0004024994347707008

Note that \(\pi\) is predefined in Julia. (You can also use the Greek letter for it by typing \pi and then pressing Tab.) Here we calculate the number of accurate digits in p.

@show accurate_digits = -log(10,rel_accuracy);
accurate_digits = -(log(10, rel_accuracy)) = 3.395234725174716