These are different, but you could probably put an argument that the tag wikis need help.
precision refers to the range of numbers that can be represented - often quoted in terms of significant figures (or, when dealing with binary numbers, significant bits). Accuracy is related to numbers that are within that precision but still can't be represented exactly.
For example, an IEEE754 Double has 53 significant bits of mantissa precision (and 11 bits of exponent precision), giving (according to Wikipedia) 15-17 significant decimal figures. But the number one tenth (decimal 0.1), which with one significant decimal figure is well within that precision, can't be represented exactly as an IEEE754 Double.
You could argue that they are technically the same thing (0.1 requires infinitely many significant bits when stored in binary, and not enough bits is a precision thing), but they cause different types of problems that have different types of solutions.
Although various programming languages apply some magic to display the value 0.1 instead of 0.1000000000000000055511151231257827021181583404541015625, accuracy problems can cause cumulative errors in calculations:
>>> a = sum([0.1]*10)
>>> b = 0.1*10
>>> a
0.9999999999999999
>>> b
1.0
>>> a == b
False
The solution to these is to either:
- Rearrange your arithmetic to do less, bigger calculations (such as one multiplication instead of 10 additions), or
- Use a type that can accurately represent the values you care about (eg, a decimal float type or a fraction/rational type)
Precision problems will cause problems like overflow or underflow (overflowing IEEE754 operations tend to return ±infinity, but other numeric types might have different behavior like 'wrapping around'):
>>> m = sys.float_info.max
>>> m
1.7976931348623157e+308
>>> 2*m
inf
The solution to these is to use a wider precision type, or even an unlimited precision type (like Python's int
or Java's BigInteger
, or extended precision floats like C's long double
).