Skip to content

Commit 34f6dc4

Browse files
committed
Improve sign and payload handling
1 parent 91051ef commit 34f6dc4

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

extra/decimal_printer.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,24 @@ def decimal32_summary(valobj, internal_dict):
1313
bits = val.GetChildMemberWithName("bits_").GetValueAsUnsigned()
1414

1515
sign = bits & 2147483648 != 0
16-
# TODO(mborland): Add Payloads to NANS
1716
if bits & 2013265920 == 2013265920:
1817

1918
if bits & 2113929216 == 2113929216:
20-
result = "SNAN"
19+
result = "-SNAN" if sign else "SNAN"
2120
isnan = True
2221
elif bits & 2080374784 == 2080374784:
23-
result = "QNAN"
22+
result = "-SNAN" if sign else "QNAN"
2423
isnan = True
2524
elif bits & 2080374784 == 2013265920:
26-
if sign:
27-
result = "-INF"
28-
else:
29-
result = "INF"
25+
result = "-INF" if sign else "INF"
3026
else:
3127
raise ValueError("Unknown Finite Value")
3228

3329
if isnan:
3430
payload = bits & 8388607
3531
if payload > 0:
36-
result += str(payload)
32+
result += '(' + str(payload) + ')'
33+
3734
else:
3835
# See decimal32_t::to_components()
3936
d32_comb_11_mask = 1610612736
@@ -50,8 +47,9 @@ def decimal32_summary(valobj, internal_dict):
5047
if significand == 0:
5148
result = "0.0e+0"
5249
else:
53-
# TODO(mborland): Make sure we preserve the amount of precision
5450
n_digits = len(str(abs(significand)))
51+
52+
# If there is no fractional component we want to remove the decimal point and zero
5553
if n_digits > 1:
5654
normalized = significand / (10 ** (n_digits - 1))
5755
total_exp = exp + n_digits - 1

0 commit comments

Comments
 (0)