cmath.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:ouroboros 作者: pybee 项目源码 文件源码
def _log(z):
    abs_x = abs(z.real)
    abs_y = abs(z.imag)

    if abs_x > _LARGE_INT or abs_y > _LARGE_INT:
        return complex(math.log(math.hypot(abs_x/2, abs_y/2)) + _LOG_2,
                       math.atan2(z.imag, z.real))
    if abs_x < _DBL_MIN and abs_y < _DBL_MIN:
        if abs_x > 0 or abs_y > 0:
            return complex(math.log(math.hypot(math.ldexp(abs_x, _DBL_MANT_DIG),
                                    math.ldexp(abs_y, _DBL_MANT_DIG)))
                           - _DBL_MANT_DIG * _LOG_2,
                           math.atan2(z.imag, z.real))
        raise ValueError

    rad, phi = polar(z)
    return complex(math.log(rad), phi)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号