Python arithmetic with small numbers

前端 未结 7 1277
面向向阳花
面向向阳花 2021-01-18 00:59

I am getting the following unexpected result when I do arithmetic with small numbers in Python:

>>> sys.float_info
sys.float_info(max=1.797693134862         


        
7条回答
  •  温柔的废话
    2021-01-18 01:44

    you can handle those. note that

    >>> 1.e-17 == 0
    False
    

    and

    >>> 1.e-17 + 1.e-18
    1.1e-17
    

    you simply cannot handle 1-1e-17, because the mantissa won't fit in the finite precision

提交回复
热议问题