Products of small float32 values.

Can someone explain what is going on here? In [153]: small = ones(1, dtype='float32') In [154]: small Out[154]: array([ 1.], dtype=float32) In [155]: small*1e-45 Out[155]: array([ 1.40129846e-45], dtype=float32) In [156]: small*1e-46 Out[156]: array([ 0.], dtype=float32) I would expect float32 to be able to represent numbers with exponents as small as -127. Thanks, Dave Cook

Hi, On Wed, Oct 2, 2013 at 6:00 PM, Dave Cook <daverz@gmail.com> wrote:
Can someone explain what is going on here?
In [153]:
small = ones(1, dtype='float32')
In [154]:
small
Out[154]:
array([ 1.], dtype=float32)
In [155]:
small*1e-45
Out[155]:
array([ 1.40129846e-45], dtype=float32)
In [156]:
small*1e-46
Out[156]:
array([ 0.], dtype=float32)
I would expect float32 to be able to represent numbers with exponents as small as -127.
Is it possible you are thinking of 2**-126 rather than 10**-126? In [3]: print np.finfo(np.float32) Machine parameters for float32 --------------------------------------------------------------------- precision= 6 resolution= 1.0000000e-06 machep= -23 eps= 1.1920929e-07 negep = -24 epsneg= 5.9604645e-08 minexp= -126 tiny= 1.1754944e-38 maxexp= 128 max= 3.4028235e+38 nexp = 8 min= -max --------------------------------------------------------------------- In [4]: 2**-126 Out[4]: 1.1754943508222875e-38 So I think your 10**-45 was already 'subnormal' and then 10**-46 went down to 0... Cheers, Matthew

On Wed, Oct 2, 2013 at 6:06 PM, Matthew Brett <matthew.brett@gmail.com>wrote:
Is it possible you are thinking of 2**-126 rather than 10**-126?
Yup, brainfart...
In [3]: print np.finfo(np.float32) Machine parameters for float32 --------------------------------------------------------------------- precision= 6 resolution= 1.0000000e-06 machep= -23 eps= 1.1920929e-07 negep = -24 epsneg= 5.9604645e-08 minexp= -126 tiny= 1.1754944e-38 maxexp= 128 max= 3.4028235e+38 nexp = 8 min= -max ---------------------------------------------------------------------
Thanks for that. Dave Cook
participants (2)
-
Dave Cook
-
Matthew Brett