Some built-in functions (like Exp
) give an arbitrary precision result, even when the argument is a machine precision number. Example:
Exp[-10.] // Precision
MachinePrecision
Exp[-1000.] // Precision
12.9546
I can of course Clip
and Chop
the result to a machine precision number, but I would like to avoid the cost of arbitrary precision calculations (and unpacking, if the argument is a packed array) in the first place. For example here:
x = Range[-10.^6, 10.^6];
Timing[y = Exp[-x^2/2];]
PackedArrayQ[y]
The calculation takes 7s on my PC (machine precision calculation would take ~0.1s) and the result isn't a packed array.
Compile
, is it of interest? $\endgroup$System
SetSystemOptions["CatchMachineUnderflow" -> False];` works perfectly. I did look for similar questions, but didn't find the one you linked. It's obviously a duplicate. Should delete it myself or vote to close? $\endgroup$Compile
can also work, and if you don't feel like setting a global option, theCompile
option"RuntimeOptions" -> {"CatchMachineUnderflow" -> False}
could be a good alternative. $\endgroup$