Scientific notation for exact numbers?
You can try $Post
or $PrePrint
:
$Post
num = 37894580188800000000000000000000000000000000000000;
$Post = N; (* apply `N` to every output expression *)
num
3.78945801888`*^49
Precision[num]
∞
Reset
$Post = .
num
37894580188800000000000000000000000000000000000000
$PrePrint
Apply N
to every expression before it is printed -- "Show exact quantities by their numerical value:"
$PrePrint = Replace[#,
x_?NumericQ :> If[Precision[x] == ∞, N[x], N[x, Precision[x]]], All] &;
num
foo[{num, bar[10`20], 2`2}]
You can create wrapper function to do this:
MakeBoxes[inexactForm[e_], StandardForm] ^:= Internal`InheritedBlock[{Integer},
Unprotect[Integer];
MakeBoxes[i_Integer, StandardForm] ^:= With[{n=N@i}, MakeBoxes[n, StandardForm]];
MakeBoxes[e, StandardForm]
]
Then:
inexactForm[
a[
37894580188800000000000000000000000000000000000000,
37894580188800000000000000000000000000000000000000
]
]
a[3.78946*10^49,3.78946*10^49]
You could just modify the display Format
of specific functions/patterns:
Unprotect[BesselJ, BesselY];
Format[BesselJ[n_, z_ /; Precision[z] == ∞]] := BesselJ[n, N[z]]
Format[BesselY[n_, z_ /; Precision[z] == ∞]] := BesselY[n, N[z]]
Protect[BesselJ, BesselY];
then we get a more legible display without modifying any variables:
test
(* (BesselJ[-(3/4), 5.40477*10^9 Mrest] BesselY[-(1/4), 5.40477*10^9 Mrest] +
BesselJ[3/4, 5.40477*10^9 Mrest] BesselY[1/4, 5.40477*10^9 Mrest]) (Quantity[...]) *)