diff --git a/docs/setup.rst b/docs/setup.rst index de7339bd..efaa76fd 100644 --- a/docs/setup.rst +++ b/docs/setup.rst @@ -84,7 +84,7 @@ Python interpreter and do the following:: Using gmpy2 (optional) ---------------------- -If `gmpy2 `_ version 2.2.0 or later is +If `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 +`_ 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 ------------- diff --git a/mpmath/ctx_mp_python.py b/mpmath/ctx_mp_python.py index e231c991..0f742b03 100644 --- a/mpmath/ctx_mp_python.py +++ b/mpmath/ctx_mp_python.py @@ -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 diff --git a/mpmath/libmp/libmpf.py b/mpmath/libmp/libmpf.py index 266ee394..4e652b5f 100644 --- a/mpmath/libmp/libmpf.py +++ b/mpmath/libmp/libmpf.py @@ -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) diff --git a/mpmath/tests/test_format.py b/mpmath/tests/test_format.py index 52c3b43d..00ac61f2 100644 --- a/mpmath/tests/test_format.py +++ b/mpmath/tests/test_format.py @@ -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' diff --git a/pyproject.toml b/pyproject.toml index bebbc8f0..5867537f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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']