AFAIAC, we can restrict ourselves to BigInt, BigInt64Array and BigUint64Array (the standard set) without enabling quickjs-specific extensions (BigFloat, BigDecimal, use math, ...).
Currently I implemented the JS -> Python conversion. I am unsure about the other direction:
Python integers unlimited both in size and precision.
JS has no upper limit on standard numbers, though it uses float semantics for large numbers (e-formatting, precision loss, Infinity, ...).
The current implementation in module.c uses a C long for the conversion and thus fails for large integers (actually, this can be considered a bug in the current python_to_quickjs_possible).
>>> import quickjs
>>> ctx = quickjs.Context()
>>> ctx.set("a", 10**100)
OverflowError: Python int too large to convert to C long
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: <method 'set' of '_quickjs.Context' objects> returned a result with an error set
So I see three possible paths:
Explicitely forbid Python -> JS conversions if the number does not fit in a C long
pro: easy
con: does not use Python/JS capabilities to their full potential (introduces arbitrary limitation)
Allow them, using a Python float / C double for the conversion
pro: respects JS number semantics (float-like numbers)
con: does not respect Python integer semantics (unlimited precision)
Allow them, converting to BigInt
pro: exact
con: imprevisible behavior (target type depends on the input value; BigInt's and standard numbers are not freely mixable in JS).
NOTE: currently, in the other direction, a Python float is returned when the value does not fit in a C long. So the second path may be the most reasonable. EDIT: see the tentative implementation in #71.
Fix #61.
AFAIAC, we can restrict ourselves to
BigInt
,BigInt64Array
andBigUint64Array
(the standard set) without enablingquickjs
-specific extensions (BigFloat
,BigDecimal
,use math
, ...).Currently I implemented the JS -> Python conversion. I am unsure about the other direction:
module.c
uses a C long for the conversion and thus fails for large integers (actually, this can be considered a bug in the currentpython_to_quickjs_possible
).So I see three possible paths:
BigInt
BigInt
's and standard numbers are not freely mixable in JS).NOTE: currently, in the other direction, a Python float is returned when the value does not fit in a C long. So the second path may be the most reasonable. EDIT: see the tentative implementation in #71.