python类log()的实例源码

test_functions.py 文件源码 项目:twic_close_reading 作者: jarmoza 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_log():
    mp.dps = 15
    assert log(1) == 0
    for x in [0.5, 1.5, 2.0, 3.0, 100, 10**50, 1e-50]:
        assert log(x).ae(math.log(x))
        assert log(x, x) == 1
    assert log(1024, 2) == 10
    assert log(10**1234, 10) == 1234
    assert log(2+2j).ae(cmath.log(2+2j))
    # Accuracy near 1
    assert (log(0.6+0.8j).real*10**17).ae(2.2204460492503131)
    assert (log(0.6-0.8j).real*10**17).ae(2.2204460492503131)
    assert (log(0.8-0.6j).real*10**17).ae(2.2204460492503131)
    assert (log(1+1e-8j).real*10**16).ae(0.5)
    assert (log(1-1e-8j).real*10**16).ae(0.5)
    assert (log(-1+1e-8j).real*10**16).ae(0.5)
    assert (log(-1-1e-8j).real*10**16).ae(0.5)
    assert (log(1j+1e-8).real*10**16).ae(0.5)
    assert (log(1j-1e-8).real*10**16).ae(0.5)
    assert (log(-1j+1e-8).real*10**16).ae(0.5)
    assert (log(-1j-1e-8).real*10**16).ae(0.5)
    assert (log(1+1e-40j).real*10**80).ae(0.5)
    assert (log(1j+1e-40).real*10**80).ae(0.5)
    # Huge
    assert log(ldexp(1.234,10**20)).ae(log(2)*1e20)
    assert log(ldexp(1.234,10**200)).ae(log(2)*1e200)
    # Some special values
    assert log(mpc(0,0)) == mpc(-inf,0)
    assert isnan(log(mpc(nan,0)).real)
    assert isnan(log(mpc(nan,0)).imag)
    assert isnan(log(mpc(0,nan)).real)
    assert isnan(log(mpc(0,nan)).imag)
    assert isnan(log(mpc(nan,1)).real)
    assert isnan(log(mpc(nan,1)).imag)
    assert isnan(log(mpc(1,nan)).real)
    assert isnan(log(mpc(1,nan)).imag)
test_functions.py 文件源码 项目:twic_close_reading 作者: jarmoza 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_complex_functions():
    for x in (list(range(10)) + list(range(-10,0))):
        for y in (list(range(10)) + list(range(-10,0))):
            z = complex(x, y)/4.3 + 0.01j
            assert exp(mpc(z)).ae(cmath.exp(z))
            assert log(mpc(z)).ae(cmath.log(z))
            assert cos(mpc(z)).ae(cmath.cos(z))
            assert sin(mpc(z)).ae(cmath.sin(z))
            assert tan(mpc(z)).ae(cmath.tan(z))
            assert sinh(mpc(z)).ae(cmath.sinh(z))
            assert cosh(mpc(z)).ae(cmath.cosh(z))
            assert tanh(mpc(z)).ae(cmath.tanh(z))
test_functions.py 文件源码 项目:twic_close_reading 作者: jarmoza 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_aliases():
    assert ln(7) == log(7)
    assert log10(3.75) == log(3.75,10)
    assert degrees(5.6) == 5.6 / degree
    assert radians(5.6) == 5.6 * degree
    assert power(-1,0.5) == j
    assert fmod(25,7) == 4.0 and isinstance(fmod(25,7), mpf)
test_functions.py 文件源码 项目:twic_close_reading 作者: jarmoza 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_misc_bugs():
    # test that this doesn't raise an exception
    mp.dps = 1000
    log(1302)
    mp.dps = 15
functions.py 文件源码 项目:twic_close_reading 作者: jarmoza 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def log10(ctx, x):
    return ctx.log(x, 10)
math2.py 文件源码 项目:twic_close_reading 作者: jarmoza 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _mathfun_n(f_real, f_complex):
    def f(*args, **kwargs):
        try:
            return f_real(*(float(x) for x in args))
        except (TypeError, ValueError):
            return f_complex(*(complex(x) for x in args))
    f.__name__ = f_real.__name__
    return f

# Workaround for non-raising log and sqrt in Python 2.5 and 2.4
# on Unix system
math2.py 文件源码 项目:twic_close_reading 作者: jarmoza 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def math_log(x):
        if x <= 0.0:
            raise ValueError("math domain error")
        return math.log(x)
antlang.py 文件源码 项目:antlang4python 作者: AntLang-Software 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def my_log(x, y = None):
    if y is None:
        return log(x)
    else:
        return log(y, x)
PyAntLang.py 文件源码 项目:antlang4python 作者: AntLang-Software 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def log(x, y = None):
    if y is None:
        return math_lib.log(x)
    else:
        return math_lib.log(y, x)
test_functions.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_log():
    mp.dps = 15
    assert log(1) == 0
    for x in [0.5, 1.5, 2.0, 3.0, 100, 10**50, 1e-50]:
        assert log(x).ae(math.log(x))
        assert log(x, x) == 1
    assert log(1024, 2) == 10
    assert log(10**1234, 10) == 1234
    assert log(2+2j).ae(cmath.log(2+2j))
    # Accuracy near 1
    assert (log(0.6+0.8j).real*10**17).ae(2.2204460492503131)
    assert (log(0.6-0.8j).real*10**17).ae(2.2204460492503131)
    assert (log(0.8-0.6j).real*10**17).ae(2.2204460492503131)
    assert (log(1+1e-8j).real*10**16).ae(0.5)
    assert (log(1-1e-8j).real*10**16).ae(0.5)
    assert (log(-1+1e-8j).real*10**16).ae(0.5)
    assert (log(-1-1e-8j).real*10**16).ae(0.5)
    assert (log(1j+1e-8).real*10**16).ae(0.5)
    assert (log(1j-1e-8).real*10**16).ae(0.5)
    assert (log(-1j+1e-8).real*10**16).ae(0.5)
    assert (log(-1j-1e-8).real*10**16).ae(0.5)
    assert (log(1+1e-40j).real*10**80).ae(0.5)
    assert (log(1j+1e-40).real*10**80).ae(0.5)
    # Huge
    assert log(ldexp(1.234,10**20)).ae(log(2)*1e20)
    assert log(ldexp(1.234,10**200)).ae(log(2)*1e200)
    # Some special values
    assert log(mpc(0,0)) == mpc(-inf,0)
    assert isnan(log(mpc(nan,0)).real)
    assert isnan(log(mpc(nan,0)).imag)
    assert isnan(log(mpc(0,nan)).real)
    assert isnan(log(mpc(0,nan)).imag)
    assert isnan(log(mpc(nan,1)).real)
    assert isnan(log(mpc(nan,1)).imag)
    assert isnan(log(mpc(1,nan)).real)
    assert isnan(log(mpc(1,nan)).imag)
test_functions.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_complex_functions():
    for x in (list(range(10)) + list(range(-10,0))):
        for y in (list(range(10)) + list(range(-10,0))):
            z = complex(x, y)/4.3 + 0.01j
            assert exp(mpc(z)).ae(cmath.exp(z))
            assert log(mpc(z)).ae(cmath.log(z))
            assert cos(mpc(z)).ae(cmath.cos(z))
            assert sin(mpc(z)).ae(cmath.sin(z))
            assert tan(mpc(z)).ae(cmath.tan(z))
            assert sinh(mpc(z)).ae(cmath.sinh(z))
            assert cosh(mpc(z)).ae(cmath.cosh(z))
            assert tanh(mpc(z)).ae(cmath.tanh(z))
test_functions.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_aliases():
    assert ln(7) == log(7)
    assert log10(3.75) == log(3.75,10)
    assert degrees(5.6) == 5.6 / degree
    assert radians(5.6) == 5.6 * degree
    assert power(-1,0.5) == j
    assert fmod(25,7) == 4.0 and isinstance(fmod(25,7), mpf)
test_functions.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_misc_bugs():
    # test that this doesn't raise an exception
    mp.dps = 1000
    log(1302)
    mp.dps = 15
functions.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def log10(ctx, x):
    return ctx.log(x, 10)
math2.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def _mathfun_n(f_real, f_complex):
    def f(*args, **kwargs):
        try:
            return f_real(*(float(x) for x in args))
        except (TypeError, ValueError):
            return f_complex(*(complex(x) for x in args))
    f.__name__ = f_real.__name__
    return f

# Workaround for non-raising log and sqrt in Python 2.5 and 2.4
# on Unix system
math2.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def math_log(x):
        if x <= 0.0:
            raise ValueError("math domain error")
        return math.log(x)
runzmq.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def mathlog(a):return mathclog(a).real
page.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def mathlog(a):return mathclog(a).real
base.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def mathlog(a):return mathclog(a).real
AdaBoost.py 文件源码 项目:statistical-learning-methods-note 作者: ysh329 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def computeBaseClassifierCoefficient(self, classifierIdx):
        '''
        ???????????????(?0??)???????????? alpha ?
        :param classifierIdx: ???????(?0??)
        :return:
        '''
        self.alphaList[classifierIdx] = (1.0 / 2 * \
                                         cmath.log((1.0-self.eList[classifierIdx])/self.eList[classifierIdx], cmath.e)\
                                         ).real


问题


面经


文章

微信
公众号

扫码关注公众号