# Explanation of the precision and the accuracy used by Wolfram Mathematica when performing arithmetic operations on floating point numbers

The numerical value for the precision in mathematica is given out by $MachinePrecision, and this is also the number of relevant digits showed in the output console when performing a computation with floating points. Howewer, by executing for example RealDigits[Pi, 10, 300] I can see 3 hundrends decimals, each of them correct. Moreover even the multiplication RealDigits[Pi*3, 10, 300] is perfectly correct on any of the decimal, and it is not just approximated on the first $MachinePrecision ones.

I am wondering why this is possible, what is actually the real grade of precision when doing arithmetic operation on Mathematical. My vision is not clear right now. Thank you.

• This seems like it is better suited for the Mathematica.se forum; it does not come across as a math question per se. – Daniel Lichtblau Dec 26 '19 at 19:23

$MachinePrecision is the precision of machine numbers. You get a machine number when you e.g. enter it as 3.5234 instead of e.g. 35234/10000. Also, default precision for N is $MachinePrecision, so e.g. N will give you a machine representation of 3.

When you enter Pi or 3Pi, you get an exact number. It's a symbolic representation of a number, which can be evaluated to arbitrary precision using N. Similarly, you get Sqrt if you evaluate e.g. 25^(1/4), while evaluation of 25.0^(1/4) will give you machine-precision approximation 2.23606797749979. So you'll get:

(* Exact number *)
Pi // FullForm
(* Machine number *)
N[Pi] // FullForm
(* Arbitrary-precision number (this one with 30 decimal digits) *)
N[Pi, 30] // FullForm


$$\pi$$

3.141592653589793

3.141592653589793238462643383279502884197169399375105815120830.

To avoid confusion, note that FullForm shows more digits than the number precision actually is. They are the internal detail of implementation of the number storage and are printed for user to be able to save and then restore the exact same value as current session has. To see the numbers in their actual precision, omit the call to FullForm:

(* Exact number *)
Pi
(* Machine number *)
N[Pi]
(* Arbitrary-precision number (this one with 30 decimal digits) *)
N[Pi, 30]


$$\pi$$

3.14159265358979

3.14159265358979323846264338328

To see your example in the context of machine precision, try evaluating RealDigits[Pi*3., 10, 300] instead of RealDigits[Pi*3, 10, 300] (note the difference: 3. vs 3). Also try the arbitrary-precision version: RealDigits[Pi*3.011, 10, 300] (or replace 11 with your desired precision of the input number).

• Thank Ruslan, this helped me a lot! It is impossible to evaluate a MachineNumber with N[] and a Precision greater than $\texttt{\$MachinePrecision}\$? – FRANCESCO Dec 20 '19 at 16:57
• I'm not sure what you mean. A machine number is already the result of truncation of precision. You can convert it to an arbitrary-precision number using SetPrecision, but this won't improve its precision with respect to the value that it already approximates – just let further computations consider and store more of its significant digits. – Ruslan Dec 20 '19 at 17:24
• 30 digit version needs work... $$\pi=3.1415926535897932384$$$$62643383279502884197$$$$1693993751058$$$$\boldsymbol{2097494459230...}$$ Also it is north of 60 digits shown ... – user645636 Dec 20 '19 at 17:33
• @RoddyMacPhee it's FullForm. If you omit this call and simply output the result of N, you'll get 3.14159265358979323846264338328` – Ruslan Dec 20 '19 at 17:34
• @RoddyMacPhee I've edited the post to note this. – Ruslan Dec 20 '19 at 17:37