Consider a very simple calculation: $231 \times (2.54) ^ 3$, which is the number of cubic cm in a US gallon.
On my phone app calculator I got the exact answer, which is $3785.411784$.
On Mathematica, doing the same calculation 231 * (2.54)^3
I got 3785.41
.
Even with N[231 * 2.54^3, 100]
etc. I got the same (imprecise) answer.
By converting the whole calculation to involve integers (254^3 * 231 /1000000)
the answer was exact.
The Precision
function kept indicating MachinePrecision
, even when using N[]
with a large number of significant figures.
How can I increase the precision beyond MachinePrecision
for trivial calculations like this?
What if I have more complicated calculations involving exponents or other?
I would want to avoid accumulating loss of precision in each calculation.
N[]
won't convert machine precision to arbitrary precision. You could try showing the full result:Style[231*2.54^3, PrintPrecision -> 17]
orFullForm[231*2.54^3]
. Or you could feed arbitrary-precision numbers as input:231*2.54`100^3
(tho 100 digits is overkill). $\endgroup$Style[0.4 {1 - $MachineEpsilon/2, 1}, PrintPrecision -> 16]
and retry with17
.) The default value forPrintPrecision
is6
. $\endgroup$