Wolfram Language & System 10.0 (2014)|Legacy Documentation
The Wolfram Language works with both exact quantities and approximate numbers. Using N, you can obtain a numerical approximation to an exact quantity with any desired precision or accuracy. In calculations involving arbitrary-precision approximate numbers, the Wolfram Language tracks the propagation of the numerical error. The use of high-precision numbers can yield accurate results where other numerical systems fail.
Use N to get a numerical approximation to an exact number:
In the Wolfram Language, "precision" effectively refers to the number of significant figures. You can specify the precision of the result with the second argument of N. Get a result with precision 50:
"Accuracy" effectively refers to the number of correct digits after the decimal point. Give as the second argument of N to get a result with accuracy a. The means any precision. For example, specify an accuracy of 10:
The Wolfram Language works with exact numbers and with two different types of approximate numbers: machine-precision numbers that take advantage of specialized hardware for fast arithmetic on your computer, and arbitrary-precision numbers that are correct to a specified number of digits.
Numbers entered in decimal notation are normally interpreted as machine-precision numbers, which have precision MachinePrecision:
By default, the result of N is a machine-precision number:
Specifying that has precision 10 implies a certain value for its accuracy, which in this case is less than 10. The difference (Precision[x]-Accuracy[x]) is essentially the scale, or magnitude, of the number, which is given by RealExponent[x]:
MachinePrecision is considered less precise than any other precision. This is because, while machine-precision numbers always store slightly under 16 digits, no specific number of those digits are known to be correct.
Here, all of the digits in the machine-precision result are correct (use InputForm to display all the nonzero digits of an approximate number):
To be sure of n correct digits, use N[expr,n]. Get 10 correct digits:
Here, it is impossible for N to obtain a result with 6 digits of precision because the input is a machine-precision number, which is considered less than any other precision:
If you know that an approximate number num is more precise than Precision[num] indicates, you can explicitly set its precision using SetPrecision. Get an arbitrary-precision number with 20 digits of precision corresponding to the machine-precision number 0.5:
When an expression contains approximate numbers, you do not normally need to use N. The Wolfram Language automatically computes an approximate result, and determines the precision of the result by considering the precision of the input. In general, the precision of the result will differ from the precision of any part of the input.
Use Precision on the most recent output () to see that the Wolfram Language was able to determine that the result has 11 digits of precision:
When you require results to a specific precision or accuracy, it is usually best to give exact inputs and use N. This is because N will sometimes temporarily compute at a higher precision than you request in order to obtain a result that satisfies your specification.