Subject: Re: How is memory allocated in recursive XSLT templates?
From: "Rashmi Rubdi" <rashmi.sub@xxxxxxxxx>
Date: Wed, 2 May 2007 16:03:27 -0400
|
On 5/2/07, Abel Braaksma <abel.online@xxxxxxxxx> wrote:
PS:
Rashmi Rubdi wrote:
>
> I was trying to achieve the equivalent of the recursive Factorial
> function illustrated here with procedural programming:
> http://www.oopweb.com/Algorithms/Documents/PLDS210/Volume/recursion.html
>
<xsl:function name="f:fac" as="xs:integer">
<xsl:param name="nr" as="xs:integer" />
<xsl:sequence select="if($nr = 0) then 1 else f:fac($nr -1) *
$nr" />
</xsl:function>
Which gives in a split second for:
<xsl:sequence select="f:fac(100)" />
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
Wow , that is amazing!
I have written this in Java, my program fails to calculate anything
greater than factorial 16 which is 2004189184 , I think the
limitation is occurring because I've used an int data type.
May be if I change it to long or BigInteger, I might get a bigger
number but i'll test the limits :-)
Thanks a lot for the solution, I will try your code and see if I can
compare the limits with 2 programming languages, just for the sake of
curiosity.
Not that bad for an interpreted language, my calculator is not that
precise...
Cheers,
-- Abel
-Regards
Rashmi
| Current Thread |
|
Rashmi Rubdi - 2 May 2007 20:03:50 -0000 <=
|
|