----- Original Message ----- 
From: "Edward Wijaya" <[EMAIL PROTECTED]>
To: <inline@perl.org>
Sent: Saturday, March 26, 2005 7:32 PM
Subject: How can I get Inline::C to deal with BIG number?


> Hi,
>
> I have the following code that uses Inline::C to compute factorial.
> The problem is that whenever I use really large N (>500) it began to
return
> "INF". On average I need to deal with N=1000-2000.
>
> Additionally I have already done these things as an attempt to solve
> the problem, but again no avail:
>
> 1. added Math::Pari module
> 2. use "double" and even "long double" for type declaration on C section.
>
> Can anybody suggest what's the way to deal with this?
>

Normally you would simply use Math::Pari or Math::GMP to do it - without
invoking Inline::C at all.

If you want to do it using Inline::C, then normally you would write C code
that accesses the appropriate functions in the PariGP C library (as distinct
from Math::Pari) or the GMP library (as distinct from Math::GMP) - or you
could access some other bignum C library - or you could write your own
Inline::C functions that perform the bignum arithmetic.

If you want to access Math::Pari functions from Inline::C, then I think you
need to do it as a "callback" to perl - see 'perldoc perlcall' for
documentation regarding callbacks. (This approach does not make much sense
to me in this particular instance.)

If long doubles are big enough for what you want, then you could write your
Inline::C functions using long doubles. To return those "long doubles" to
perl I would convert them to C strings using C's sprintf() function, and
return those strings.

Cheers,
Rob

Reply via email to