I have problem in Mathematica with unnecessary rounding which is caused by high precision.
For example I have value a = 2.052685846*10^-1865
, when I make b = 1 - a
the result is b == 1.
What can I do to have a better precision, without rounding?
2 Answers
Works for me on Mathematica 8.0.
however, you can try using N
to have the value number with the number of significant digits as you like:
b = N[ 1-a, 2000]
$2000$ digits after the decimal point in this case Mathematica does not perform rounding to $1$.
-
$\begingroup$ @Ziva
N[ 1-a, 2000]
yields the same result as1 - a
for me (V9.0.1, 8.0.4, 7.0.0). I don't get 2000 digitsl I get 1880 plus 27 insignificant digits. $\endgroup$ Mar 22, 2014 at 1:34
I suspect that there may be an issue of $MaxMachineNumber
in play here. On my machine $MaxMachineNumber
is 1.79769*10^308
therefore:
MachineNumberQ[a = 2.052685846*10^-1865]
Precision[1 - a]
False 1880.64
This means that 1 - a
is done with arbitrary precision arithmetic and all digits are displayed. However if a smaller exponent is used such that a
is machine size only machine precision arithmetic will be used, and the result is 1.
:
MachineNumberQ[a = 2.052685846*10^-186] (* note -186 *)
1 - a
Precision @ %
True 1. MachinePrecision
b = 1. - a
? The decimal point after the 1 makes all the difference. $\endgroup$