本文整理汇总了Python中sympy.mpmath.libmp.prec_to_dps函数的典型用法代码示例。如果您正苦于以下问题:Python prec_to_dps函数的具体用法?Python prec_to_dps怎么用?Python prec_to_dps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了prec_to_dps函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _print_Real
def _print_Real(self, expr):
prec = expr._prec
if prec < 5:
dps = 0
else:
dps = prec_to_dps(expr._prec)
if self._settings["full_prec"] == True:
strip = False
elif self._settings["full_prec"] == False:
strip = True
elif self._settings["full_prec"] == "auto":
strip = self._print_level > 1
return mlib.to_str(expr._mpf_, dps, strip_zeros=strip)
开发者ID:Praveen-Ramanujam,项目名称:MobRAVE,代码行数:13,代码来源:str.py
示例2: _print_Float
def _print_Float(self, expr):
prec = expr._prec
if prec < 5:
dps = 0
else:
dps = prec_to_dps(expr._prec)
if self._settings["full_prec"] == True:
strip = False
elif self._settings["full_prec"] == False:
strip = True
elif self._settings["full_prec"] == "auto":
strip = self._print_level > 1
rv = mlib.to_str(expr._mpf_, dps, strip_zeros=strip)
if rv.startswith('-.0'):
rv = '-0.' + rv[3:]
elif rv.startswith('.0'):
rv = '0.' + rv[2:]
return rv
开发者ID:cknoll,项目名称:sympy,代码行数:18,代码来源:str.py
示例3: _print_Float
def _print_Float(self, expr):
# Based off of that in StrPrinter
dps = prec_to_dps(expr._prec)
str_real = mlib.to_str(expr._mpf_, dps, strip_zeros=True)
# Must always have a mul symbol (as 2.5 10^{20} just looks odd)
separator = r" \times "
if self._settings['mul_symbol'] is not None:
separator = self._settings['mul_symbol_latex']
if 'e' in str_real:
(mant, exp) = str_real.split('e')
if exp[0] == '+':
exp = exp[1:]
return r"%s%s10^{%s}" % (mant, separator, exp)
elif str_real == "+inf":
return r"\infty"
elif str_real == "-inf":
return r"- \infty"
else:
return str_real
开发者ID:imranmanzoor,项目名称:sympy,代码行数:24,代码来源:latex.py
示例4: _print_Real
def _print_Real(self, expr):
dps = prec_to_dps(expr._prec)
r = mlib.to_str(expr._mpf_, repr_dps(expr._prec))
return "%s('%s', prec=%i)" % (expr.__class__.__name__, r, dps)
开发者ID:Sumith1896,项目名称:sympy-polys,代码行数:4,代码来源:repr.py
示例5: round
def round(x, p=0):
"""Return x rounded to the given decimal place. If x is not an Expr,
Python's round function is employed.
Examples
========
>>> from sympy import round, pi, S, Number
>>> round(S(10.5))
11.
>>> round(pi)
3.
>>> round(pi, 2)
3.14
If x is not a SymPy Expr then Python's round is used and it returns
a Python type, not a SymPy Number:
>>> isinstance(round(543210, -2), Number)
False
>>> round(S(543210), -2)
5.432e+5
>>> _.is_Number
True
"""
from sympy.functions.elementary.exponential import log
from sympy.mpmath.libmp import prec_to_dps
if not isinstance(x, Expr):
return _pyround(x, p)
if not x.is_number:
raise TypeError('%s is not a number' % x)
if not x.is_real:
raise TypeError("can't convert complex to int")
if not x:
return x
p = int(p)
precs = [f._prec for f in x.atoms(C.Float)]
dps = prec_to_dps(max(precs)) if precs else None
xpos = abs(x.n())
try:
mag_first_dig = int(ceil(log10(xpos)))
except (ValueError, OverflowError):
mag_first_dig = int(ceil(C.Float(mpf_log(xpos._mpf_, 53))/log(10)))
# check that we aren't off by 1
if (xpos/10**mag_first_dig) >= 1:
mag_first_dig += 1
assert .1 <= (xpos/10**mag_first_dig) < 1
allow = digits_needed = mag_first_dig + p
if dps is not None and allow > dps:
allow = dps
mag = Pow(10, p) # magnitude needed to bring digit p to units place
x += 1/(2*mag) # add the half for rounding
i10 = 10*mag*x.n((dps if dps is not None else digits_needed) + 1)
rv = Integer(i10)//10
q = 1
if p > 0:
q = mag
elif p < 0:
rv /= mag
rv = Rational(rv, q)
if rv.is_Integer:
# use str or else it won't be a float
return C.Float(str(rv), digits_needed)
else:
return C.Float(rv, allow)
开发者ID:Misbah6317,项目名称:sympy,代码行数:68,代码来源:miscellaneous.py
注:本文中的sympy.mpmath.libmp.prec_to_dps函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论