Skip to content

Commit ff94486

Browse files
committed
Add decimal_fast128_t pretty printer
1 parent 265ff0a commit ff94486

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

examples/debugger.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ int main()
4444

4545
debug_values<boost::decimal::decimal_fast32_t>();
4646
debug_values<boost::decimal::decimal_fast64_t>();
47+
debug_values<boost::decimal::decimal_fast128_t>();
4748

4849
return 0;
4950
}

extra/decimal_printer.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from detail.decode_ieee_type import decode_decimal128
88
from detail.decode_fast_type import decode_decimal_fast32
99
from detail.decode_fast_type import decode_decimal_fast64
10+
from detail.decode_fast_type import decode_decimal_fast128
1011

1112
import lldb
1213

@@ -73,7 +74,7 @@ def decimal_fast32_summary(valobj, internal_dict):
7374

7475
def decimal_fast64_summary(valobj, internal_dict):
7576
"""
76-
Custom summary for decimal_fast32_t type
77+
Custom summary for decimal_fast64_t type
7778
Displays in scientific notation
7879
"""
7980

@@ -86,6 +87,27 @@ def decimal_fast64_summary(valobj, internal_dict):
8687

8788
except Exception as e:
8889
return f"<invalid decimal_fast64_t: {e}>"
90+
def decimal_fast128_summary(valobj, internal_dict):
91+
"""
92+
Custom summary for decimal_fast128_t type
93+
Displays in scientific notation
94+
"""
95+
96+
try:
97+
val = valobj.GetNonSyntheticValue()
98+
99+
significand = val.GetChildMemberWithName("significand_")
100+
bits_high = significand.GetChildMemberWithName("high").GetValueAsUnsigned()
101+
bits_low = significand.GetChildMemberWithName("low").GetValueAsUnsigned()
102+
combined_bits = (bits_high << 64) | bits_low
103+
104+
exp = val.GetChildMemberWithName("exponent_").GetValueAsUnsigned()
105+
sign = val.GetChildMemberWithName("sign_").GetValueAsUnsigned()
106+
107+
return decode_decimal_fast128(combined_bits, exp, sign)
108+
109+
except Exception as e:
110+
return f"<invalid decimal_fast128_t: {e}>"
89111

90112
def __lldb_init_module(debugger, internal_dict):
91113
decimal32_pattern = r"^(const )?(boost::decimal::decimal32_t|(\w+::)*decimal32_t)( &| \*)?$"
@@ -94,6 +116,7 @@ def __lldb_init_module(debugger, internal_dict):
94116

95117
decimal_fast32_pattern = r"^(const )?(boost::decimal::decimal_fast32_t|(\w+::)*decimal_fast32_t)( &| \*)?$"
96118
decimal_fast64_pattern = r"^(const )?(boost::decimal::decimal_fast64_t|(\w+::)*decimal_fast64_t)( &| \*)?$"
119+
decimal_fast128_pattern = r"^(const )?(boost::decimal::decimal_fast128_t|(\w+::)*decimal_fast128_t)( &| \*)?$"
97120

98121
debugger.HandleCommand(
99122
f'type summary add -x "{decimal32_pattern}" -e -F decimal_printer.decimal32_summary'
@@ -140,6 +163,15 @@ def __lldb_init_module(debugger, internal_dict):
140163

141164
print("decimal_fast64_t printer loaded successfully")
142165

166+
debugger.HandleCommand(
167+
f'type summary add -x "{decimal_fast128_pattern}" -e -F decimal_printer.decimal_fast128_summary'
168+
)
169+
debugger.HandleCommand(
170+
f'type synthetic add -x "{decimal_fast128_pattern}" -l decimal_printer.DecimalFastSyntheticProvider'
171+
)
172+
173+
print("decimal_fast128_t printer loaded successfully")
174+
143175
class DecimalSyntheticProvider:
144176
def __init__(self, valobj, internal_dict):
145177
self.valobj = valobj

extra/detail/decode_fast_type.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,32 @@ def decode_decimal_fast64(significand, exp, sign):
6262
exp -= 398 # Bias value
6363
result = generate_string(significand, exp, sign)
6464

65+
def decode_decimal_fast128(significand, exp, sign):
66+
67+
high_bits = significand >> 64
68+
69+
# See values of non-finite masks in decimal_fast32_t.hpp
70+
if high_bits >= 2305843009213693952:
71+
isnan = False
72+
73+
if high_bits == 2305843009213693952:
74+
result = "-INF" if sign else "INF"
75+
elif high_bits >= 16140901064495857664:
76+
result = "-SNAN" if sign else "SNAN"
77+
significand ^= (16140901064495857664 << 64)
78+
isnan = True
79+
elif high_bits >= 6917529027641081856:
80+
result = "-QNAN" if sign else "QNAN"
81+
significand ^= (6917529027641081856 << 64)
82+
isnan = True
83+
else:
84+
raise ValueError("Unknown Finite Value")
85+
86+
if isnan and significand > 0:
87+
result += '(' + str(significand) + ')'
88+
89+
else:
90+
exp -= 6176 # Bias value
91+
result = generate_string(significand, exp, sign)
92+
6593
return result

0 commit comments

Comments
 (0)