Skip to content

Commit 73024d3

Browse files
author
Dorian Birraux
committed
Merge pull request #224 in LCL/wolframclientforpython from bugfix/383494-big-real-expo-dropped to master
* commit 'a8f8f440dba5333c89161f328217af8f00721288': removing unused vars for clarity Add test with big real and neg exponent. Negative exponent is dropped when deserializing big reals
2 parents b75bf76 + a8f8f44 commit 73024d3

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

wolframclient/deserializers/wxf/wxfconsumer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def consume_bigint(self, current_token, tokens, **kwargs):
154154
except ValueError:
155155
raise WolframParserException("Invalid big integer value: %s" % current_token.data)
156156

157-
BIGREAL_RE = re.compile(r"([^`]+)(`[0-9.]+){0,1}(\*\^[0-9]+){0,1}")
157+
BIGREAL_RE = re.compile(r"([^`]+)(`[0-9.]+){0,1}(\*\^){0,1}(-?[0-9]+){0,1}")
158158

159159
def consume_bigreal(self, current_token, tokens, **kwargs):
160160
"""Parse a WXF big real as a WXF serializable big real.
@@ -169,10 +169,10 @@ def consume_bigreal(self, current_token, tokens, **kwargs):
169169

170170
if match:
171171

172-
num, prec, exp = match.groups()
172+
num, _, _, exp = match.groups()
173173

174174
if exp:
175-
return decimal.Decimal("%se%s" % (num, exp[2:]))
175+
return decimal.Decimal("%se%s" % (num, exp))
176176

177177
return decimal.Decimal(num)
178178

wolframclient/tests/deserializers/wxf_deserialize.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ def test_bigreal_precision_exponent(self):
147147
res = binary_deserialize(wxf, consumer=WXFConsumer())
148148
self.assertEqual(res, decimal.Decimal("9.999999999999996843873323328588479844E+999"))
149149

150+
def test_bigreal_precision_negexponent(self):
151+
wxf = b'8:RC4.590261537982443550699999999999999999999281`19.66183743091127*^-16'
152+
res = binary_deserialize(wxf, consumer=WXFConsumer())
153+
self.assertEqual(res, decimal.Decimal('4.590261537982443550699999999999999999999281E-16'))
154+
150155
def test_empty_lists(self):
151156
value = ((), ((),), (1, ()), ())
152157
self.wxf_assert_roundtrip(value)

0 commit comments

Comments
 (0)