xsl-list
[Top] [All Lists]

Re: [xsl] How is memory allocated in recursive XSLT templates?

2007-05-02 13:03:48
On 5/2/07, Abel Braaksma <abel(_dot_)online(_at_)xs4all(_dot_)nl> 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--