Python arithmetic with small numbers

前端 未结 7 1213
面向向阳花
面向向阳花 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:28

    it should be able to handle "large" small numbers like 1e-17, shouldn't it?

    Not necessarily (it depends on the numbers). A float cannot exactly represent either 1e-17 or 1-(1e-17). In the case of the latter, the nearest number that it can represent is 1.

    I suggest you read What Every Computer Scientist Should Know About Floating-Point Arithmetic.

提交回复
热议问题