4

I am doing calculations with Python numpy. Here is a resulting numpy array:

[  5.15054786e-11   5.15251385e-11   5.15262922e-11 ...,   5.21100674e-11
5.21097550e-11   5.21088179e-11]

Those are pretty tiny. At what point should I worry about underflow in my calculations? These need to be ultra-precise. Is there a definite value range to worry about, or perhaps a reference which states this value?

ShanZhengYang
  • 16,511
  • 49
  • 132
  • 234
  • 1
    The answer depends on the type of your data. `float` and `double` have different precissions, but for `1e-11` both should work without problems. – Imanol Luengo Jan 21 '16 at 17:49
  • 5
    If you're concerned about underflow, you can use `np.seterr` to warn/raise when underflow is encountered. – Alex Riley Jan 21 '16 at 18:22

1 Answers1

6

The smallest representable normal number in a 64 bit floating point number is:

>>> 2**-1022
2.2250738585072014e-308

That range can be extended a little more using denormal numbers, which take the smallest down to:

>>> 2**(-1022 - 52)
5e-324

But:

>>> 2**(-1022 - 53)
0.0

Another relevant small number (again for 64 bit numbers) would be:

>>> 2**-52
2.220446049250313e-16

because:

>>> 1 + 2**-52
1.0000000000000002

but:

>>> 1 + 2**-53
1.0
Jaime
  • 65,696
  • 17
  • 124
  • 159