Skip to content

Commit

Permalink
Switch to r and R (for round brackets)
Browse files Browse the repository at this point in the history
  • Loading branch information
ep12 committed Dec 22, 2019
1 parent 81a9594 commit 4ff064f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions uncertainties/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,8 @@ def format_num(nom_val_main, error_main, common_exp,
and the error, superscript exponents, etc.). "L" is for a LaTeX
output. Options can be combined. "%" adds a final percent sign,
and parentheses if the shorthand notation is not used. The P
option has priority over the L option (if both are given). The "b"
option adds enclosing parenthesis with a common factor outside. "B"
option has priority over the L option (if both are given). The "r"
option adds enclosing parenthesis with a common factor outside. "R"
forces the parenthesis to also enclose the factor, which means that
you might get two pairs of parenthesis.
'''
Expand Down Expand Up @@ -1445,14 +1445,14 @@ def format_num(nom_val_main, error_main, common_exp,
nom_val_str, pm_symbol, error_str,
RIGHT_GROUPING,
exp_str, percent_str))
if 'B' in options:
if 'R' in options:
value_str = LEFT_GROUPING + value_str + RIGHT_GROUPING
else:
value_str = u''.join([nom_val_str, pm_symbol, error_str])
if percent_str:
value_str = u''.join((
LEFT_GROUPING, value_str, RIGHT_GROUPING, percent_str))
if 'b' in options or 'B' in options:
if 'r' in options or 'R' in options:
value_str = u''.join((LEFT_GROUPING, value_str, RIGHT_GROUPING))

return value_str
Expand Down Expand Up @@ -1951,9 +1951,9 @@ def __format__(self, format_spec):
mode is activated: "±" separates the nominal value from the
standard deviation, exponents use superscript characters,
etc. When "L" is present, the output is formatted with LaTeX.
The option "b" enforces surrounding brackets, but a common
The option "r" enforces surrounding brackets, but a common
factor will still be outside of the parenthesis. To have
a pair of parenthesis enclose everything, use "B".
a pair of parenthesis enclose everything, use "R".
An uncertainty which is exactly zero is represented as the
integer 0 (i.e. with no decimal point).
Expand Down Expand Up @@ -1992,7 +1992,7 @@ def __format__(self, format_spec):
(?P<uncert_prec>u?) # Precision for the uncertainty?
# The type can be omitted. Options must not go here:
(?P<type>[eEfFgG%]??) # n not supported
(?P<options>[LSPbB]*)$''',
(?P<options>[LSPrR]*)$''',
format_spec,
re.VERBOSE)

Expand Down
20 changes: 10 additions & 10 deletions uncertainties/test_uncertainties.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,8 +1856,8 @@ def test_format():
'13.6g': ' 1.20000e-34+/- 0.00000e-34',
'13.6G': ' 1.20000E-34+/- 0.00000E-34',
'.6GL': r'\left(1.20000 \pm 0.00000\right) \times 10^{-34}',
'.6GLb': r'\left(1.20000 \pm 0.00000\right) \times 10^{-34}',
'.6GLB': r'\left(\left(1.20000 \pm 0.00000\right) \times 10^{-34}\right)',
'.6GLr': r'\left(1.20000 \pm 0.00000\right) \times 10^{-34}',
'.6GLR': r'\left(\left(1.20000 \pm 0.00000\right) \times 10^{-34}\right)',
},

(float('nan'), 100): { # NaN *nominal value*
Expand Down Expand Up @@ -1914,13 +1914,13 @@ def test_format():
'': 'inf+/-123456789.0', # Similar to '{}'.format(123456789.)
'g': '(inf+/-1.23457)e+08', # Similar to '{:g}'.format(123456789.)
'.1e': '(inf+/-1.2)e+08',
'.1eb': '(inf+/-1.2)e+08',
'.1eB': '((inf+/-1.2)e+08)',
'.1er': '(inf+/-1.2)e+08',
'.1eR': '((inf+/-1.2)e+08)',
'.1E': '(%s+/-1.2)E+08' % Inf_EFG,
'.1ue': '(inf+/-1)e+08',
'.1ueL': r'\left(\infty \pm 1\right) \times 10^{8}',
'.1ueLb': r'\left(\infty \pm 1\right) \times 10^{8}',
'.1ueLB': r'\left(\left(\infty \pm 1\right) \times 10^{8}\right)',
'.1ueLr': r'\left(\infty \pm 1\right) \times 10^{8}',
'.1ueLR': r'\left(\left(\infty \pm 1\right) \times 10^{8}\right)',
'10.1e': ' inf+/- 1.2e+08',
'10.1eL': r' \infty \pm 1.2 \times 10^{8}'
},
Expand All @@ -1930,8 +1930,8 @@ def test_format():
'.1E': '%s+/-%s' % (Inf_EFG, Inf_EFG),
'.1ue': 'inf+/-inf',
'EL': r'\infty \pm \infty',
'ELB': r'\left(\infty \pm \infty\right)',
'ELb': r'\left(\infty \pm \infty\right)',
'ELR': r'\left(\infty \pm \infty\right)',
'ELr': r'\left(\infty \pm \infty\right)',
},

# Like the tests for +infinity, but for -infinity:
Expand Down Expand Up @@ -1974,8 +1974,8 @@ def test_format():
# with a non-zero uncertainty:
(724.2, 26.4): {
'': '724+/-26',
'b': '(724+/-26)',
'B': '(724+/-26)',
'r': '(724+/-26)',
'R': '(724+/-26)',
},
(724, 0): {
'': '724.0+/-0'
Expand Down

0 comments on commit 4ff064f

Please sign in to comment.