From d3812b11949966914c30d0eced65677a77526fbe Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 21 Aug 2026 08:25:46 +0300 Subject: [PATCH] Amend bc96a889 --- mpmath/libmp/libmpf.py | 5 ++++- mpmath/tests/test_format.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mpmath/libmp/libmpf.py b/mpmath/libmp/libmpf.py index a3c58d6e..2af9c362 100644 --- a/mpmath/libmp/libmpf.py +++ b/mpmath/libmp/libmpf.py @@ -1728,7 +1728,7 @@ def format_digits(num, format_dict, prec, rnd, _pretty_repr_dps, unique): 10, round_nearest) prev_digits = digits prev_exp = exp - while True: + while dps > 1: dps -= 1 new_digits, new_exp = round_digits(num, digits, exp, dps, 10, round_down) @@ -1743,6 +1743,9 @@ def format_digits(num, format_dict, prec, rnd, _pretty_repr_dps, unique): break prev_digits = new_digits prev_exp = new_exp + else: + digits = new_digits + exp = new_exp else: num = mpf_pos(num, prec, rnd) # workaround issue 1158 # Here be dragons. diff --git a/mpmath/tests/test_format.py b/mpmath/tests/test_format.py index 18aa3960..8830e03f 100644 --- a/mpmath/tests/test_format.py +++ b/mpmath/tests/test_format.py @@ -472,6 +472,8 @@ def test_mpf_fmt_cpython(): assert f'{mp.pi}' == '3.14159265358979' mp.pretty_dps = 'repr' assert f'{mp.pi}' == '3.1415926535897931' + mp.shortest_str = True + assert f'{mp.mpf("1e100000")}' == '1e+100000' @given(fmt_str(types=list('fFeEgG%') + ['']),