On Thu, Sep 19, 2024 at 04:08:34PM +0200, Christian Grün scripsit: [snip]
Integers in BaseX are limited to 64bit (that’s something the spec allows). You can use decimals to work with greater numbers:
declare variable $factorial := fn($x) { if($x > 1) then $x * $factorial($x - 1) else $x }; $factorial(1000.0)
If you need even larger results, you can use a tail-call-optimized variant…
declare variable $factorial := fn($x, $result) { if($x > 1) then $factorial($x - 1, $x * $result) else $result }; $factorial(100000.0, 1)
…or fold-left:
fold-left(1 to 100000, 1.0, op('*'))
Hope this helps,
Most helpful; thank you! It feels like my understanding of how types and processing interact has improved.
-- Graydon