Karim BELABAS on Mon, 4 Dec 2000 13:18:58 +0100 (MET)

 Re: long long with libpari

```[Janet:]
> I'm wondering if there is a way to use really big integers with libpari
> (where a really big integer is one that requires more space than a long).
> It seems like stoi is the only function to stuff an integer into a GEN
> (perhaps I'm wrong on this point?), and this automatically converts the
> integer to a long first.  Is there anything I can do to get bigger
> integers?

You can convert from a string:

GEN x = lisexpr("123456768912312312391273198372131");

But most "interesting" integers are the result of some computation, so you
can program that computation, e.g

GEN x = addis( gpowgs(stoi(3), 1000), 7 );  /* 3^1000 + 7 */

If what you want is a low-level function to convert from "long long" to PARI
integer, you'll have to copy the code from stoi and modify it to your
liking. Something like

GEN
lltoi(long long x)
{
GEN y;

if ((x >> BITS_IN_LONG) == 0) return stoi((long)x);
y = cgeti(4);
if (x > 0)
{
y[1] = evalsigne(1)  | evallgefint(4);
}
else
{
y[1] = evalsigne(-1) | evallgefint(4);
x = -x;
}
y[2] = x >> BITS_IN_LONG;
y[3] = (long)x;
return y;
}

[untested, but should work after minimal tweaking...]

Cheers,

Karim.
--
Karim Belabas                    email: Karim.Belabas@math.u-psud.fr
Dep. de Mathematiques, Bat. 425
Universite Paris-Sud             Tel: (00 33) 1 69 15 57 48
F-91405 Orsay (France)           Fax: (00 33) 1 69 15 60 19
--