Handling very small numbers in python

前端 未结 2 1768
故里飘歌
故里飘歌 2021-02-14 17:56

I am currently working with very small numbers in my python program, e.g.

x = 200 + 2e-26

One solution is to work with logarithmic values whic

2条回答
  •  日久生厌
    2021-02-14 18:34

    Consider trying out the mpmath package.

    >>> from mpmath import mpf, mpc, mp
    >>> mp.dps = 40
    >>> mpf(200) + mpf(2e-26) + mpc(1j)
    mpc(real='200.0000000000000000000000000200000000000007', imag='1.0')
    

    Mostly accurate and can handle complex numbers, more details in the documentation.

提交回复
热议问题