Merge pull request #1026 from skirpichev/misc
test / coverage (push) Failing after 0s
test / docs (push) Failing after 0s
test / linter (push) Failing after 0s
test / tests (false, false, 3.14t) (push) Has been skipped
test / tests (false, false, 3.10) (push) Has been skipped
test / tests (false, false, 3.11) (push) Has been skipped
test / tests (false, false, 3.12) (push) Has been skipped
test / tests (false, false, 3.13) (push) Has been skipped
test / tests (false, false, 3.13t) (push) Has been skipped
test / tests (false, false, 3.14) (push) Has been skipped
test / tests (false, false, 3.9) (push) Has been skipped
test / tests (true, pypy3.11) (push) Has been skipped
test / tests (true, 3.14) (push) Has been skipped
Publish on PyPI / Build distributions (push) Has been cancelled
Publish on PyPI / Publish distributions to PyPI (push) Has been cancelled

Misc fixes
This commit is contained in:
Sergey B Kirpichev
2026-02-08 07:02:14 +03:00
committed by GitHub
5 changed files with 17 additions and 16 deletions
+6 -1
View File
@@ -84,7 +84,7 @@ Python interpreter and do the following::
Using gmpy2 (optional)
----------------------
If `gmpy2 <https://github.com/aleaxit/gmpy>`_ version 2.2.0 or later is
If `gmpy2 <https://github.com/gmpy2/gmpy2>`_ version 2.3.0 or later is
installed on your system, mpmath will automatically detect it and transparently
use gmpy2 integers instead of Python integers. This makes mpmath much faster,
especially at high precision (approximately above 100 digits).
@@ -96,6 +96,11 @@ Using the gmpy2 backend can be disabled by setting the ``MPMATH_NOGMPY``
environment variable. Note that the mode cannot be switched during runtime;
mpmath must be re-imported for this change to take effect.
Alternatively, you can use `python-gmp
<https://github.com/diofant/python-gmp>`_ extension. The ``BACKEND`` value
will be equal to 'gmp' in this case. If both extensions are installed on your
system, the gmpy2 will be preferred.
Running tests
-------------
+4 -5
View File
@@ -443,8 +443,7 @@ class _mpf(mpnumeric):
>>> f'{x:.15b}'
'-1.001111000000110p+0'
Alternate form (``'#'`` option) adds ``0b`` prefix.
Alternate form (``'#'`` option) works like for ``'a'`` type.
"""
_, _, (prec, rounding) = self._ctxdata
@@ -753,10 +752,10 @@ class _mpc(mpnumeric):
"""
``mpc`` objects allow for formatting similar to Python
:external:class:`complex`, specified in :external:ref:`formatspec`.
All of Python's format types are supported, with the exception of
``'n'``. Also available additional options and formating types,
accepted by :func:`mpmath.mpf.__format__`.
All ``mpf``'s format types and options are supported, with
the exception for ``'%'`` format type, ``'='`` alignment and
zero padding.
"""
ctx = self.context
_, _, (prec, rounding) = self._ctxdata
+1 -7
View File
@@ -1532,10 +1532,6 @@ def format_fixed(s, dps, rnd=round_nearest):
return int_part, frac_part
_MAP_FMT_EXP = {'E': 'E', 'e': 'e', 'G': 'E', 'g': 'e',
'A': 'P', 'a': 'p', 'B': 'p', 'b': 'p', '': 'e'}
def format_scientific(s, dps, rnd=round_nearest):
base = 10
@@ -1672,10 +1668,8 @@ def format_digits(num, format_dict, prec, rnd, _pretty_repr_dps):
elif fmt_type == 'b':
int_part, frac_part, exponent = format_binary(num, dps, rnd=rnd)
if frac_part:
if frac_part or format_dict['alternate']:
frac_part = '.' + frac_part
if format_dict['alternate']:
int_part = '0b' + int_part
else: # fixed-point formats
int_part, frac_part = format_fixed(num, dps, rnd=rnd)
+3 -1
View File
@@ -902,7 +902,9 @@ def test_binary_fmt():
assert f'{x:b}' == '1.1p+1'
assert f'{x:.2b}' == '1.10p+1'
assert f'{x:+.2b}' == '+1.10p+1'
assert f'{x:#.2b}' == '0b1.10p+1'
assert f'{x:#.2b}' == '1.10p+1'
assert f'{x:.0b}' == '1p+2'
assert f'{x:#.0b}' == '1.p+2'
x = mp.mpf(0)
assert f'{x:.2b}' == '0.00p+0'
+3 -2
View File
@@ -35,9 +35,10 @@ Documentation = 'http://mpmath.org/doc/current/'
tests = ['pytest>=6', 'numpy', 'packaging', 'pytest-timeout',
'matplotlib', 'pexpect', 'ipython', 'hypothesis']
develop = ['mpmath[tests]', 'flake518>=1.5', 'pytest-cov>=7', 'wheel', 'build']
gmpy2 = ['gmpy2>=2.3.0a1,<2.3.0a2']
gmpy2 = ['gmpy2>=2.3']
gmpy = ['mpmath[gmpy2]']
gmp = ['python-gmp>=0.4']
gmp = ['python-gmp>=0.5; python_version>="3.11"',
'python-gmp>=0.4; python_version<"3.11"']
docs = ['sphinx', 'matplotlib', 'sphinxcontrib-autoprogram']
ci = ['pytest-xdist', 'diff_cover']