"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "mpmath/ctx_mp.py" between
mpmath-0.19.tar.gz and mpmath-1.0.0.tar.gz

About: mpmath is a Python library for arbitrary-precision floating-point arithmetic.

ctx_mp.py  (mpmath-0.19):ctx_mp.py  (mpmath-1.0.0)
skipping to change at line 577 skipping to change at line 577
make this function useful for printing collections of numbers make this function useful for printing collections of numbers
(lists, matrices, etc). (lists, matrices, etc).
If *x* is a list or tuple, :func:`~mpmath.nstr` is applied recursively If *x* is a list or tuple, :func:`~mpmath.nstr` is applied recursively
to each element. For unrecognized classes, :func:`~mpmath.nstr` to each element. For unrecognized classes, :func:`~mpmath.nstr`
simply returns ``str(x)``. simply returns ``str(x)``.
The companion function :func:`~mpmath.nprint` prints the result The companion function :func:`~mpmath.nprint` prints the result
instead of returning it. instead of returning it.
The keyword arguments *strip_zeros*, *min_fixed*, *max_fixed*
and *show_zero_exponent* are forwarded to :func:`~mpmath.libmp.to_str`.
The number will be printed in fixed-point format if the position
of the leading digit is strictly between min_fixed
(default = min(-dps/3,-5)) and max_fixed (default = dps).
To force fixed-point format always, set min_fixed = -inf,
max_fixed = +inf. To force floating-point format, set
min_fixed >= max_fixed.
>>> from mpmath import * >>> from mpmath import *
>>> nstr([+pi, ldexp(1,-500)]) >>> nstr([+pi, ldexp(1,-500)])
'[3.14159, 3.05494e-151]' '[3.14159, 3.05494e-151]'
>>> nprint([+pi, ldexp(1,-500)]) >>> nprint([+pi, ldexp(1,-500)])
[3.14159, 3.05494e-151] [3.14159, 3.05494e-151]
>>> nstr(mpf("5e-10"), 5)
'5.0e-10'
>>> nstr(mpf("5e-10"), 5, strip_zeros=False)
'5.0000e-10'
>>> nstr(mpf("5e-10"), 5, strip_zeros=False, min_fixed=-11)
'0.00000000050000'
>>> nstr(mpf(0), 5, show_zero_exponent=True)
'0.0e+0'
""" """
if isinstance(x, list): if isinstance(x, list):
return "[%s]" % (", ".join(ctx.nstr(c, n, **kwargs) for c in x)) return "[%s]" % (", ".join(ctx.nstr(c, n, **kwargs) for c in x))
if isinstance(x, tuple): if isinstance(x, tuple):
return "(%s)" % (", ".join(ctx.nstr(c, n, **kwargs) for c in x)) return "(%s)" % (", ".join(ctx.nstr(c, n, **kwargs) for c in x))
if hasattr(x, '_mpf_'): if hasattr(x, '_mpf_'):
return to_str(x._mpf_, n, **kwargs) return to_str(x._mpf_, n, **kwargs)
if hasattr(x, '_mpc_'): if hasattr(x, '_mpc_'):
return "(" + mpc_to_str(x._mpc_, n, **kwargs) + ")" return "(" + mpc_to_str(x._mpc_, n, **kwargs) + ")"
if isinstance(x, basestring): if isinstance(x, basestring):
 End of changes. 2 change blocks. 
0 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)