Skip to content

Accuracy

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

Accuracy[x]

Returns the number of digits of accuracy in x — equal to Precision[x] − Log10[Abs[x]]. Exact numbers (including exact 0) return Infinity. Inexact zeros are finite: machine 0. returns ≈ 323.607; MPFR 0 of precision p returns p digits.

Examples (6)

Every input below was run against the current Mathilda build and its output recorded.

Applications (6)

In[1]:= Accuracy[1.5]
Out[1]= 15.7785

In[2]:= Accuracy[5]
Out[2]= Infinity

In[3]:= Accuracy[N[Pi, 30]]
Out[3]= 29.6058

In[4]:= Accuracy[N[10^20, 30]]
Out[4]= 10.103

In[5]:= Accuracy[N[1/10^20, 30]]
Out[5]= 50.103

In[6]:= Accuracy[0.]
Out[6]= 323.607

Implementation notes

builtin_accuracy (src/precision.c) delegates to accuracy_of, which returns the number of correct digits to the right of the decimal point. Exact quantities (integers, bigints, exact rationals, strings, symbols, exact zero) return Infinity. For inexact reals it returns MachinePrecisionDigits - log10|x|; for EXPR_MPFR it uses the value's actual precision (mpfr_get_prec / log2(10)) minus log10|x| (inexact zero gets the precision in digits directly). Complex[re, im] and general function arguments recurse and take the minimum (precision_min) over components/arguments. Accuracy is ATTR_LISTABLE, so it threads over lists.

Attributes: Listable, Protected.

References

Notes & additional examples

Notes

Accuracy gives the number of digits to the right of the decimal point, i.e. the digit count relative to the absolute (not relative) magnitude, satisfying Accuracy[x] == Precision[x] - Log10[Abs[x]]. Exact numbers have Infinity accuracy. For a fixed precision of 30 digits, the same Pi-style relative precision yields very different accuracies as magnitude changes: N[10^20, 30] has only 10.1 digits past the point, while N[1/10^20, 30] has 50.1. Inexact zero is the special case — machine 0. returns the finite value 323.607 rather than Infinity.