6

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.

Niki Estner
  • 36,101
  • 3
  • 92
  • 152
  • The only thing I can think of at the moment is Compile, is it of interest? – xzczd Jan 09 '15 at 13:47
  • 1
    Thanks @OleksandrR., SystemSetSystemOptions["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? – Niki Estner Jan 09 '15 at 13:59
  • 1
    We may as well VTC so that this can serve as another pointer to help other people search in the future. As @xzczd says, Compile can also work, and if you don't feel like setting a global option, the Compile option "RuntimeOptions" -> {"CatchMachineUnderflow" -> False} could be a good alternative. – Oleksandr R. Jan 09 '15 at 14:00

0 Answers0