Skip to content

Commit 849e185

Browse files
committed
Relax requirements on precision format, allow 0-prefixes
Closes mpmath#915
1 parent 4c9a2ef commit 849e185

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

mpmath/libmp/libmpf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ def from_str(x, prec=0, rnd=round_fast, base=0):
14001400
(?P<zeropad>0)?
14011401
(?P<width>0|[1-9][0-9]*)?
14021402
(?P<thousands_separators>[,_])?
1403-
(?:\.(?P<precision>0|[1-9][0-9]*))?
1403+
(?:\.(?P<precision>[0-9]+))?
14041404
(?P<rounding>[UDYZN])?
14051405
(?P<type>[aAbeEfFgG%])?
14061406
""", re.DOTALL | re.VERBOSE).fullmatch

mpmath/tests/test_format.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def fmt_str(draw, types='fFeE', for_complex=False):
6262
res += gchar
6363

6464
# Precision
65-
prec = draw(st.sampled_from(['']*7 + list(map(str, range(40)))))
65+
prec = draw(st.sampled_from(['']*7 + list(map(str, range(40)))
66+
+ ['0' + str(_) for _ in range(40)]))
6667
if prec:
6768
res += '.' + prec
6869

@@ -468,6 +469,7 @@ def test_mpf_fmt_cpython():
468469
allow_infinity=True,
469470
allow_subnormal=True))
470471
@example(fmt='.0g', x=9.995074823339339e-05) # issue 880
472+
@example(fmt='.016f', x=0.1) # issue 915
471473
def test_mpf_floats_bulk(fmt, x):
472474
'''
473475
These are additional random tests that check that mp.mpf and fp.mpf yield

0 commit comments

Comments
 (0)