1- # decimal_printer.py
1+ # Copyright 2025 Matt Borland
2+ # Distributed under the Boost Software License, Version 1.0.
3+ # https://www.boost.org/LICENSE_1_0.txt
24
5+ from detail .decode_decimal32 import decode_decimal32
36import lldb
47
58def decimal32_summary (valobj , internal_dict ):
@@ -11,56 +14,8 @@ def decimal32_summary(valobj, internal_dict):
1114 try :
1215 val = valobj .GetNonSyntheticValue ()
1316 bits = val .GetChildMemberWithName ("bits_" ).GetValueAsUnsigned ()
17+ return decode_decimal32 (bits )
1418
15- sign = bits & 2147483648 != 0
16- isnan = False
17-
18- if bits & 2013265920 == 2013265920 :
19-
20- if bits & 2113929216 == 2113929216 :
21- result = "-SNAN" if sign else "SNAN"
22- isnan = True
23- elif bits & 2080374784 == 2080374784 :
24- result = "-SNAN" if sign else "QNAN"
25- isnan = True
26- elif bits & 2080374784 == 2013265920 :
27- result = "-INF" if sign else "INF"
28- else :
29- raise ValueError ("Unknown Finite Value" )
30-
31- if isnan :
32- payload = bits & 8388607
33- if payload > 0 :
34- result += '(' + str (payload ) + ')'
35-
36- else :
37- # See decimal32_t::to_components()
38- d32_comb_11_mask = 1610612736
39- if bits & d32_comb_11_mask == d32_comb_11_mask :
40- implied_bit = 8388608
41- significand = implied_bit | (bits & 2097151 )
42- exp = (bits & 534773760 ) >> 21
43- else :
44- significand = bits & 8388607
45- exp = (bits & 2139095040 ) >> 23
46-
47- exp -= 101 # Bias Value
48-
49- if significand == 0 :
50- result = "0.0e+0"
51- else :
52- n_digits = len (str (abs (significand )))
53-
54- # If there is no fractional component we want to remove the decimal point and zero
55- if n_digits > 1 :
56- normalized = significand / (10 ** (n_digits - 1 ))
57- total_exp = exp + n_digits - 1
58- else :
59- normalized = significand
60- total_exp = exp
61- result = f"{ '-' if sign else '' } { normalized :.{n_digits - 1 }f} e{ total_exp :+} "
62-
63- return result
6419 except Exception as e :
6520 return f"<invalid decimal32_t: { e } >"
6621
0 commit comments