Global precision setting
How do I tell mathematica that all numbers e.g. 1.5 are actually 20 Digits precision? SetPrecision on all numbers or add the `20 everywhere?
You could force this with $PreRead
. This naive definition is likely inefficient and probably breaks a number of corner cases I have not considered, but here is a rough demonstration:
$PreRead = (# /.
s_String /;
StringMatchQ[s, NumberString] &&
Precision@ToExpression@s == MachinePrecision :> s <> "`20." &);
3/1.5 + Pi/7
Precision[%]
2.4487989505128276055 20.0879
As Alexey notes this breaks if the machine number string already has a "NumberMark" after it e.g. 1.23`
. One could use a more precise string replacement to avoid this.
A different approach is to process at the expression rather than box level, though this simple first attempt probably fails in some cases as well:
$Pre = Function[Null,
Unevaluated[#] /. r_Real?MachineNumberQ :> RuleCondition@SetPrecision[r, 25],
HoldAllComplete]
Now:
MachineNumberQ[2.2]
ToString[3.14]
False "3.140000000000000124344979"
There is a quick-n-dirty solution. Set
$MinPrecision = 100
And then enter numbers something like
x = 1.01`2;
You will be getting warnings as
Precision::precsm: Requested precision 2.` is smaller than $MinPrecision.
Using $MinPrecision instead.
but in this way you if you want to change precision you just change $MinPrecision
value.
In[21]:= x
Out[21]= 1.\
0100000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000