| John Cremona on Fri, 06 Nov 2015 16:38:52 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: real polynomials |
On 6 November 2015 at 15:34, Karim Belabas
<Karim.Belabas@math.u-bordeaux.fr> wrote:
> * 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:
Thanks Karim, I will use this.
>
> 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));
> }
>
I will give you a laugh by showing you my own version:
GEN dbltorat(double x) // assumes x=a/2^e
{
long e;
GEN res = cgetg(3, t_FRAC);
if (x==0)
{
gel(res,1) = cgeti(0);
gel(res,2) = cgeti(1);
}
else
{
gel(res,1) = mantissa_real(dbltor(x), &e);
gel(res,2) = cgeti(2<<e);
}
return res;
}
(tested! a little)
In answer to Bill, it may be that the rational I create this way cause
problems as coefficients of a polynomial.
> (untested :-)
>
> Cheers,
>
> K.B.
John
> --
> 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]
> `
>