On Wed, Sep 18, 2024 at 01:08:17PM +0200, Christian Grün scripsit:
In addition, XQuery 4 will allow all of us to write self-referencing variable declarations (it’s already supported by the latest snapshot):
declare variable $factorial := fn($x) { if($x > 1) then $x + $factorial($x - 1) else $x }; $factorial(5)
If I use $x * $factorial($x - 1)
I get an out-of-range error as of $factorial(21).
declare variable $factorial := fn($x) as xs:double { if($x > 1) then $x * $factorial($x - 1) else $x };
goes until $factorial(171) gives INF.
If I were to be so unfortunate as to need larger factorials, is there a better approach?
It doesn't look like the math module has factorials and it does look like it uses xs:double for math:pow(); on the other hand, XQuery isn't meant for numerical analysis.
Thanks! Graydon