示例#1
0
def evalf_log(expr, prec, options):
    arg = expr.args[0]
    workprec = prec + 10
    xre, xim, xacc, _ = evalf(arg, workprec, options)

    if xim:
        # XXX: use get_abs etc instead
        re = evalf_log(
            C.log(C.Abs(arg, evaluate=False), evaluate=False), prec, options)
        im = mpf_atan2(xim, xre or fzero, prec)
        return re[0], im, re[2], prec

    imaginary_term = (mpf_cmp(xre, fzero) < 0)

    re = mpf_log(mpf_abs(xre), prec, rnd)
    size = fastlog(re)
    if prec - size > workprec:
        # We actually need to compute 1+x accurately, not x
        arg = C.Add(S.NegativeOne, arg, evaluate=False)
        xre, xim, _, _ = evalf_add(arg, prec, options)
        prec2 = workprec - fastlog(xre)
        # xre is now x - 1 so we add 1 back here to calculate x
        re = mpf_log(mpf_abs(mpf_add(xre, fone, prec2)), prec, rnd)

    re_acc = prec

    if imaginary_term:
        return re, mpf_pi(prec), re_acc, prec
    else:
        return re, None, re_acc, None
示例#2
0
文件: evalf.py 项目: Eskatrem/sympy
def evalf_log(expr, prec, options):
    arg = expr.args[0]
    workprec = prec + 10
    xre, xim, xacc, _ = evalf(arg, workprec, options)

    if xim:
        # XXX: use get_abs etc instead
        re = evalf_log(
            C.log(C.Abs(arg, evaluate=False), evaluate=False), prec, options)
        im = mpf_atan2(xim, xre or fzero, prec)
        return re[0], im, re[2], prec

    imaginary_term = (mpf_cmp(xre, fzero) < 0)

    re = mpf_log(mpf_abs(xre), prec, rnd)
    size = fastlog(re)
    if prec - size > workprec:
        # We actually need to compute 1+x accurately, not x
        arg = C.Add(S.NegativeOne, arg, evaluate=False)
        xre, xim, _, _ = evalf_add(arg, prec, options)
        prec2 = workprec - fastlog(xre)
        # xre is now x - 1 so we add 1 back here to calculate x
        re = mpf_log(mpf_abs(mpf_add(xre, fone, prec2)), prec, rnd)

    re_acc = prec

    if imaginary_term:
        return re, mpf_pi(prec), re_acc, prec
    else:
        return re, None, re_acc, None
示例#3
0
    def _set_mpc(self, val):
        prec, rounding = self.context._prec_rounding
        tol = self.context.tol

        # norm = mpc_abs(val, prec, rounding)
        # tol = mpf_max(tol, mpf_mul(norm, tol))

        re, im = val

        if mpf_lt(mpf_abs(re, prec, rounding), tol):
            re = fzero
        if mpf_lt(mpf_abs(im, prec, rounding), tol):
            im = fzero

        self.__mpc__ = (re, im)
示例#4
0
    def _set_mpc(self, val):
        prec, rounding = self.context._prec_rounding
        tol = self.context.tol

        # norm = mpc_abs(val, prec, rounding)
        # tol = mpf_max(tol, mpf_mul(norm, tol))

        re, im = val

        if mpf_lt(mpf_abs(re, prec, rounding), tol):
            re = fzero
        if mpf_lt(mpf_abs(im, prec, rounding), tol):
            im = fzero

        self.__mpc__ = (re, im)
示例#5
0
文件: evalf.py 项目: fxkr/sympy
def get_abs(expr, prec, options):
    re, im, re_acc, im_acc = evalf(expr, prec+2, options)
    if not re:
        re, re_acc, im, im_acc = im, im_acc, re, re_acc
    if im:
        return libmp.mpc_abs((re, im), prec), None, re_acc, None
    else:
        return mpf_abs(re), None, re_acc, None
示例#6
0
def get_abs(expr, prec, options):
    re, im, re_acc, im_acc = evalf(expr, prec + 2, options)
    if not re:
        re, re_acc, im, im_acc = im, im_acc, re, re_acc
    if im:
        return libmp.mpc_abs((re, im), prec), None, re_acc, None
    else:
        return mpf_abs(re), None, re_acc, None
示例#7
0
    def _set_mpf(self, val):
        prec, rounding = self.context._prec_rounding
        tol = self.context.tol

        if mpf_lt(mpf_abs(val, prec, rounding), tol):
            self.__mpf__ = fzero
        else:
            self.__mpf__ = val
示例#8
0
    def _set_mpf(self, val):
        prec, rounding = self.context._prec_rounding
        tol = self.context.tol

        if mpf_lt(mpf_abs(val, prec, rounding), tol):
            self.__mpf__ = fzero
        else:
            self.__mpf__ = val
示例#9
0
 def __abs__(self):
     return Real._new(mlib.mpf_abs(self._mpf_), self._prec)
示例#10
0
文件: numbers.py 项目: NO2/sympy
 def __abs__(self):
     return Real._new(mlib.mpf_abs(self._mpf_), self._prec)