Karim Belabas on Fri, 06 Nov 2015 16:34:40 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: real polynomials


* John Cremona [2015-11-06 14:44]:
> Thanks for the helpful comments.  I don't need multiplicities, and in
> fact all I need is to know whether there are any roots at all in
> (-oo,oo) or (-oo,0] or [0,oo).
> At present the coeffs are converted from C doubles.  My pari
> programming skills are rather basic so almost all the program uses
> plain C types and I only convert to GEN for this one test.  Perhaps I
> should be more brave...

Maybe the following function will be of interest:

GEN
dbltorat(double x)
{
  pari_sp av = avma;
  GEN z;

  if (!x) return gen_0;
  
  z = utoi( dblmantissa(x) ); if (x < 0) setsigne(z, -1);
  return gerepileupto(av, gmul2n(z, dblexpo(x) - 63));
}

(untested :-)

Cheers,

    K.B.
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite de Bordeaux         Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]
`