Skip to content

Commit 265ff0a

Browse files
committed
Add decimal_fast64_t pretty printer
1 parent 32c8cac commit 265ff0a

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

examples/debugger.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ int main()
4343
debug_values<boost::decimal::decimal128_t>();
4444

4545
debug_values<boost::decimal::decimal_fast32_t>();
46+
debug_values<boost::decimal::decimal_fast64_t>();
4647

4748
return 0;
4849
}

extra/decimal_printer.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from detail.decode_ieee_type import decode_decimal64
77
from detail.decode_ieee_type import decode_decimal128
88
from detail.decode_fast_type import decode_decimal_fast32
9+
from detail.decode_fast_type import decode_decimal_fast64
10+
911
import lldb
1012

1113
def decimal32_summary(valobj, internal_dict):
@@ -69,12 +71,29 @@ def decimal_fast32_summary(valobj, internal_dict):
6971
except Exception as e:
7072
return f"<invalid decimal_fast32_t: {e}>"
7173

74+
def decimal_fast64_summary(valobj, internal_dict):
75+
"""
76+
Custom summary for decimal_fast32_t type
77+
Displays in scientific notation
78+
"""
79+
80+
try:
81+
val = valobj.GetNonSyntheticValue()
82+
significand = val.GetChildMemberWithName("significand_").GetValueAsUnsigned()
83+
exp = val.GetChildMemberWithName("exponent_").GetValueAsUnsigned()
84+
sign = val.GetChildMemberWithName("sign_").GetValueAsUnsigned()
85+
return decode_decimal_fast64(significand, exp, sign)
86+
87+
except Exception as e:
88+
return f"<invalid decimal_fast64_t: {e}>"
89+
7290
def __lldb_init_module(debugger, internal_dict):
7391
decimal32_pattern = r"^(const )?(boost::decimal::decimal32_t|(\w+::)*decimal32_t)( &| \*)?$"
7492
decimal64_pattern = r"^(const )?(boost::decimal::decimal64_t|(\w+::)*decimal64_t)( &| \*)?$"
7593
decimal128_pattern = r"^(const )?(boost::decimal::decimal128_t|(\w+::)*decimal128_t)( &| \*)?$"
7694

7795
decimal_fast32_pattern = r"^(const )?(boost::decimal::decimal_fast32_t|(\w+::)*decimal_fast32_t)( &| \*)?$"
96+
decimal_fast64_pattern = r"^(const )?(boost::decimal::decimal_fast64_t|(\w+::)*decimal_fast64_t)( &| \*)?$"
7897

7998
debugger.HandleCommand(
8099
f'type summary add -x "{decimal32_pattern}" -e -F decimal_printer.decimal32_summary'
@@ -112,6 +131,15 @@ def __lldb_init_module(debugger, internal_dict):
112131

113132
print("decimal_fast32_t printer loaded successfully")
114133

134+
debugger.HandleCommand(
135+
f'type summary add -x "{decimal_fast64_pattern}" -e -F decimal_printer.decimal_fast64_summary'
136+
)
137+
debugger.HandleCommand(
138+
f'type synthetic add -x "{decimal_fast64_pattern}" -l decimal_printer.DecimalFastSyntheticProvider'
139+
)
140+
141+
print("decimal_fast64_t printer loaded successfully")
142+
115143
class DecimalSyntheticProvider:
116144
def __init__(self, valobj, internal_dict):
117145
self.valobj = valobj

extra/detail/decode_fast_type.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,31 @@ def decode_decimal_fast32(significand, exp, sign):
3535
result = generate_string(significand, exp, sign)
3636

3737
return result
38+
39+
def decode_decimal_fast64(significand, exp, sign):
40+
41+
# See values of non-finite masks in decimal_fast32_t.hpp
42+
if significand >= 2305843009213693952:
43+
isnan = False
44+
45+
if significand == 2305843009213693952:
46+
result = "-INF" if sign else "INF"
47+
elif significand >= 16140901064495857664:
48+
result = "-SNAN" if sign else "SNAN"
49+
significand ^= 16140901064495857664
50+
isnan = True
51+
elif significand >= 6917529027641081856:
52+
result = "-QNAN" if sign else "QNAN"
53+
significand ^= 6917529027641081856
54+
isnan = True
55+
else:
56+
raise ValueError("Unknown Finite Value")
57+
58+
if isnan and significand > 0:
59+
result += '(' + str(significand) + ')'
60+
61+
else:
62+
exp -= 398 # Bias value
63+
result = generate_string(significand, exp, sign)
64+
65+
return result

0 commit comments

Comments
 (0)