Bill Allombert on Fri, 10 Jun 2005 15:51:44 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: dumb question about rationals |
On Fri, Jun 10, 2005 at 02:48:48PM +0200, Vincent Torri wrote: > > >Sure, but why do you need it as a long long ? It is quite possible > >for the numerator to be too large to fit in a long long, and whatever > >you can do with a long long, you can do it with a t_INT. > > ho, ok, i've not understood that. Well, i use the program i write in a > fortran one (i have done a C-fortran interface for it). Afaik, the best > integer precision that I can have in fortran 90 is 64 bits. Try this function then: long long itoll(GEN x) { const long s = signe(x); long long lu, hu, u; if (!s) return 0LL; hu = (ulong)x[2]; if (lgefint(x) == 3) return (s>0) ? hu : -hu; else if (lgefint(x) > 4 || x[2]< 0) err(affer2); lu = (ulong)x[3]; u = (hu<<BITS_IN_LONG) + lu; return (s>0) ? u : -u; } (this assume the GMP kernel is not is use.) It has the same bug than itos, it does not accept the largest negative interger (itos(-2^31) does not return -2^31 but fails). > Btw, is there a fortran binding of PARI ? I don't think so. Cheers, Bill.