Skip to content

Commit 32c8cac

Browse files
committed
Add proper handling of non-finite decimal_fast32_t values
1 parent 4235462 commit 32c8cac

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

extra/detail/decode_fast_type.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,29 @@
99
from generate_string import generate_string
1010

1111
def decode_decimal_fast32(significand, exp, sign):
12-
return generate_string(significand, exp, sign)
1312

13+
# See values of non-finite masks in decimal_fast32_t.hpp
14+
if significand >= 536870912:
15+
isnan = False
16+
17+
if significand == 536870912:
18+
result = "-INF" if sign else "INF"
19+
elif significand >= 3758096384:
20+
result = "-SNAN" if sign else "SNAN"
21+
significand ^= 3758096384
22+
isnan = True
23+
elif significand >= 1610612736:
24+
result = "-QNAN" if sign else "QNAN"
25+
significand ^= 1610612736
26+
isnan = True
27+
else:
28+
raise ValueError("Unknown Finite Value")
29+
30+
if isnan and significand > 0:
31+
result += '(' + str(significand) + ')'
32+
33+
else:
34+
exp -= 101 # Bias value
35+
result = generate_string(significand, exp, sign)
36+
37+
return result

0 commit comments

Comments
 (0)