For a project of mine it is preferrable to set notebook precision globally. I have done so by using the answer in Global precision setting.
The idea is to dynamically create a Range from variables created with this $PreRead, but a peculiarity occurs. The below code illustrates this: a rather trivial function with input variables is SetDelayed. However, on a fresh kernel asdf does not evaluate. The global variant outside Module however works fine. Is there any way to create the below functionality using this $PreRead? Or is there an alternative to the $PreRead method that can be used interchangeably?
ClearAll["Global`*"];
myGlobalPrecision = 2 $MachinePrecision;
$PreRead = (# /.
s_String /;
StringMatchQ[s, NumberString] &&
Precision@ToExpression@s == MachinePrecision :>
s <> "`" <> ToString@Floor@myGlobalPrecision <> "." &);
asdf[PTsNo_, {xLBound_Real, xUBound_Real}] := Module[{xIncrements},
xIncrements =
Range[xLBound, xUBound, (xUBound - xLBound)/(PTsNo - 1)]
]
ListPlotResolution = 20;
SpaceLowerBound = 0;
SpaceUpperBound = 10.;
xLBoundGlobal = SpaceLowerBound;
xUBoundGlobal = SpaceUpperBound;
PTsNoGlobal = 20;
asdf[ListPlotResolution, {SpaceLowerBound/1., SpaceUpperBound/1.}]
xIncrements =
Range[xLBoundGlobal,
xUBoundGlobal, (xUBoundGlobal - xLBoundGlobal)/(PTsNoGlobal - 1)]
Integerzero when computed thus:0/1.`20. Hence the second argument toasdfis not a list ofReal. – Michael E2 Nov 26 '19 at 14:03Realness of0/1.``20? – 1010011010 Nov 26 '19 at 14:060``20represents an underlfow less than $10^{-20}$. It computes as zero plus/minus an uncertainty in arbitrary precision arithmetic. The only true (?) zero in arbitrary precision is the integer0. So as far as argument patterns go, you could usexLBound: 0 | _Real. There is alsoxLBound_?Internal`RealValuedNumberQbut it will allowIntegerandRationalarguments as well. – Michael E2 Nov 26 '19 at 14:13N[0, myGlobalPrecision]andSetPrecision[0, myGlobalPrecision]have the same problem as0/1.`20. – Michael E2 Nov 26 '19 at 14:16/1.and using your Internal`RealValuedNumberQ trick solved the problem. – 1010011010 Nov 26 '19 at 15:10